diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2004-12-17 12:32:48 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2004-12-17 12:32:48 +0000 |
commit | 9f80e375171f987aa6680e9ccd42ae599b80eca6 (patch) | |
tree | 4dfd2501f4ada04aaaa074cb5a5dda8be54fe73f /lasso | |
parent | f44d34eecbc4cf28d4831138a3b6544716c12c6d (diff) | |
download | lasso-9f80e375171f987aa6680e9ccd42ae599b80eca6.tar.gz lasso-9f80e375171f987aa6680e9ccd42ae599b80eca6.tar.xz lasso-9f80e375171f987aa6680e9ccd42ae599b80eca6.zip |
Done with the new query snippets system (everything but the IDPEntries in
<lib:AuthnRequest>). It has nested <samlp:StatusCode> support but ID-FF layer
must still be updated to produce them.
Diffstat (limited to 'lasso')
-rw-r--r-- | lasso/xml/internals.h | 2 | ||||
-rw-r--r-- | lasso/xml/lib_authn_request.c | 99 | ||||
-rw-r--r-- | lasso/xml/lib_federation_termination_notification.c | 72 | ||||
-rw-r--r-- | lasso/xml/lib_idp_entries.c | 2 | ||||
-rw-r--r-- | lasso/xml/lib_idp_entries.h | 2 | ||||
-rw-r--r-- | lasso/xml/lib_logout_request.c | 83 | ||||
-rw-r--r-- | lasso/xml/lib_register_name_identifier_request.c | 2 | ||||
-rw-r--r-- | lasso/xml/lib_status_response.c | 65 | ||||
-rw-r--r-- | lasso/xml/saml_name_identifier.c | 42 | ||||
-rw-r--r-- | lasso/xml/saml_name_identifier.h | 3 | ||||
-rw-r--r-- | lasso/xml/samlp_request_abstract.c | 49 | ||||
-rw-r--r-- | lasso/xml/samlp_response_abstract.c | 58 | ||||
-rw-r--r-- | lasso/xml/samlp_status.c | 45 | ||||
-rw-r--r-- | lasso/xml/xml.c | 50 |
14 files changed, 181 insertions, 393 deletions
diff --git a/lasso/xml/internals.h b/lasso/xml/internals.h index 65be0183..8e819465 100644 --- a/lasso/xml/internals.h +++ b/lasso/xml/internals.h @@ -72,7 +72,7 @@ void lasso_node_class_add_snippets(LassoNodeClass *klass, struct XmlSnippet *sni void lasso_node_class_add_query_snippets(LassoNodeClass *klass, struct QuerySnippet *snippets); gchar* lasso_node_build_query_from_snippets(LassoNode *node); -void lasso_node_init_from_query_fields(LassoNode *node, char **query_fields); +gboolean lasso_node_init_from_query_fields(LassoNode *node, char **query_fields); #ifdef __cplusplus } diff --git a/lasso/xml/lib_authn_request.c b/lasso/xml/lib_authn_request.c index 9c513912..5ea21838 100644 --- a/lasso/xml/lib_authn_request.c +++ b/lasso/xml/lib_authn_request.c @@ -41,7 +41,7 @@ * <xs:sequence> * <xs:element ref="Extension" minOccurs="0" maxOccurs="unbounded"/> * <xs:element ref="ProviderID"/> - * <xs:element ref="AffiliationID" minOccurs="0"/> + * <xs:element ref="AffiliationID" minOccurs="0"/> * <xs:element ref="NameIDPolicy" minOccurs="0"/> * <xs:element name="ForceAuthn" type="xs:boolean" minOccurs="0"/> * <xs:element name="IsPassive" type="xs:boolean "minOccurs="0"/> @@ -106,92 +106,48 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0} }; +static struct QuerySnippet query_snippets[] = { + { "RequestID", NULL }, + { "MajorVersion", NULL }, + { "MinorVersion", NULL }, + { "IssueInstant", NULL }, + { "ProviderID", NULL }, + { "AffiliationID", NULL }, + { "ForceAuthn", NULL }, + { "IsPassive", NULL }, + { "NameIDPolicy", NULL }, + { "ProtocolProfile", NULL }, + { "RequestAuthnContext/AuthnContextStatementRef", "AuthnContextStatementRef" }, + { "RequestAuthnContext/AuthnContextClassRef", "AuthnContextClassRef" }, + { "RequestAuthnContext/AuthnContextComparison", "AuthnContextComparison" }, + { "RelayState", NULL }, + { "Scoping/ProxyCount", "ProxyCount" }, + { "Scoping/IDPList/IDPEntries", "IDPEntries" }, + { "Scoping/IDPList/GetComplete", "GetComplete" }, + { "consent", NULL }, + { NULL, NULL } +}; + static LassoNodeClass *parent_class = NULL; static gchar* build_query(LassoNode *node) { - char *str, *t; - GString *s; - LassoLibAuthnRequest *request = LASSO_LIB_AUTHN_REQUEST(node); - - str = parent_class->build_query(node); - s = g_string_new(str); - g_free(str); - - if (request->ProviderID) { - t = xmlURIEscapeStr(request->ProviderID, NULL); - g_string_append_printf(s, "&ProviderID=%s", t); - xmlFree(t); - } - if (request->AffiliationID) - g_string_append_printf(s, "&AffiliationID=%s", request->AffiliationID); - if (request->NameIDPolicy) - g_string_append_printf(s, "&NameIDPolicy=%s", request->NameIDPolicy); - if (request->ProtocolProfile) { - t = xmlURIEscapeStr(request->ProtocolProfile, NULL); - g_string_append_printf(s, "&ProtocolProfile=%s", t); - xmlFree(t); - } - if (request->RelayState) - g_string_append_printf(s, "&RelayState=%s", request->RelayState); - if (request->consent) - g_string_append_printf(s, "&consent=%s", request->consent); - g_string_append_printf(s, "&ForceAuthn=%s", request->ForceAuthn ? "true" : "false"); - g_string_append_printf(s, "&IsPassive=%s", request->IsPassive ? "true" : "false"); - - str = s->str; - g_string_free(s, FALSE); - - return str; + return lasso_node_build_query_from_snippets(node); } static gboolean init_from_query(LassoNode *node, char **query_fields) { LassoLibAuthnRequest *request = LASSO_LIB_AUTHN_REQUEST(node); - int i; - char *t; - for (i=0; (t=query_fields[i]); i++) { - if (strncmp(t, "ProviderID=", 11) == 0) { - request->ProviderID = g_strdup(t+11); - continue; - } - if (strncmp(t, "AffiliationID=", 14) == 0) { - request->AffiliationID = g_strdup(t+14); - continue; - } - if (strncmp(t, "NameIDPolicy=", 13) == 0) { - request->NameIDPolicy = g_strdup(t+13); - continue; - } - if (strncmp(t, "ProtocolProfile=", 16) == 0) { - request->ProtocolProfile = g_strdup(t+16); - continue; - } - if (strncmp(t, "RelayState=", 11) == 0) { - request->RelayState = g_strdup(t+11); - continue; - } - if (strncmp(t, "consent=", 8) == 0) { - request->consent =g_strdup(t+8); - continue; - } - if (strncmp(t, "ForceAuthn=", 11) == 0) { - request->ForceAuthn = (strcmp(t+11, "true") == 0); - continue; - } - if (strncmp(t, "IsPassive=", 10) == 0) { - request->IsPassive = (strcmp(t+10, "true") == 0); - continue; - } - } + /* XXX needs code for Scoping, IDPList, IDPEntries... */ + lasso_node_init_from_query_fields(node, query_fields); if (request->ProviderID == NULL) return FALSE; - return parent_class->init_from_query(node, query_fields); + return TRUE; } @@ -227,6 +183,7 @@ class_init(LassoLibAuthnRequestClass *klass) lasso_node_class_set_nodename(nclass, "AuthnRequest"); lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX); lasso_node_class_add_snippets(nclass, schema_snippets); + lasso_node_class_add_query_snippets(nclass, query_snippets); } GType diff --git a/lasso/xml/lib_federation_termination_notification.c b/lasso/xml/lib_federation_termination_notification.c index 22502df9..7f9dd341 100644 --- a/lasso/xml/lib_federation_termination_notification.c +++ b/lasso/xml/lib_federation_termination_notification.c @@ -70,40 +70,41 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0} }; +static struct QuerySnippet query_snippets[] = { + { "RequestID", NULL }, + { "MajorVersion", NULL }, + { "MinorVersion", NULL }, + { "IssueInstant", NULL }, + { "ProviderID", NULL }, + { "NameIdentifier/NameQualifier", "NameQualifier" }, + { "NameIdentifier/Format", "NameFormat" }, + { "NameIdentifier/content", "NameIdentifier" }, + { "consent", NULL }, + { NULL, NULL } +}; + static LassoNodeClass *parent_class = NULL; static gchar* build_query(LassoNode *node) { - char *str, *t; - GString *s; LassoLibFederationTerminationNotification *request; - + char *s, *query; + xmlChar *t; + request = LASSO_LIB_FEDERATION_TERMINATION_NOTIFICATION(node); - str = parent_class->build_query(node); - s = g_string_new(str); - g_free(str); + query = lasso_node_build_query_from_snippets(node); - if (request->ProviderID) { - t = xmlURIEscapeStr(request->ProviderID, NULL); - g_string_append_printf(s, "&ProviderID=%s", t); + if (request->RelayState) { + t = xmlURIEscapeStr(request->RelayState, NULL); + s = g_strdup_printf(t, "%s&RelayState=%s", query, request->RelayState); xmlFree(t); + g_free(query); + query = s; } - if (request->NameIdentifier) { - t = lasso_node_build_query(LASSO_NODE(request->NameIdentifier)); - g_string_append_printf(s, "&%s", t); - g_free(t); - } - if (request->consent) - g_string_append_printf(s, "&consent=%s", request->consent); - if (request->RelayState) - g_string_append_printf(s, "&RelayState=%s", request->RelayState); - str = s->str; - g_string_free(s, FALSE); - - return str; + return query; } static gboolean @@ -118,32 +119,16 @@ init_from_query(LassoNode *node, char **query_fields) request->NameIdentifier = lasso_saml_name_identifier_new(); for (i=0; (t=query_fields[i]); i++) { - if (g_str_has_prefix(t, "ProviderID=")) { - request->ProviderID = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "consent=")) { - request->consent = g_strdup(t+8); - continue; - } - if (g_str_has_prefix(t, "NameIdentifier=")) { - request->NameIdentifier->content = g_strdup(t+15); - continue; - } - if (g_str_has_prefix(t, "NameFormat=")) { - request->NameIdentifier->Format = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "NameQualifier=")) { - request->NameIdentifier->NameQualifier = g_strdup(t+14); - continue; - } + /* RelayState is not part of <lib:FederationTerminationNotification> + * but can exists nevertheless */ if (g_str_has_prefix(t, "RelayState=")) { request->RelayState = g_strdup(t+11); continue; } } + lasso_node_init_from_query_fields(node, query_fields); + if (request->ProviderID == NULL || request->NameIdentifier->content == NULL || request->NameIdentifier->Format == NULL || @@ -153,7 +138,7 @@ init_from_query(LassoNode *node, char **query_fields) return FALSE; } - return parent_class->init_from_query(node, query_fields); + return TRUE; } @@ -184,6 +169,7 @@ class_init(LassoLibFederationTerminationNotificationClass *klass) lasso_node_class_set_nodename(nclass, "FederationTerminationNotification"); lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX); lasso_node_class_add_snippets(nclass, schema_snippets); + lasso_node_class_add_query_snippets(nclass, query_snippets); } GType diff --git a/lasso/xml/lib_idp_entries.c b/lasso/xml/lib_idp_entries.c index 214f61ea..f76472e0 100644 --- a/lasso/xml/lib_idp_entries.c +++ b/lasso/xml/lib_idp_entries.c @@ -42,7 +42,7 @@ /*****************************************************************************/ static struct XmlSnippet schema_snippets[] = { - { "IDPEntry", SNIPPET_NODE, + { "IDPEntry", SNIPPET_LIST_NODES, G_STRUCT_OFFSET(LassoLibIDPEntries, IDPEntry) }, { NULL, 0, 0} }; diff --git a/lasso/xml/lib_idp_entries.h b/lasso/xml/lib_idp_entries.h index 034b3fcc..fc872556 100644 --- a/lasso/xml/lib_idp_entries.h +++ b/lasso/xml/lib_idp_entries.h @@ -52,7 +52,7 @@ struct _LassoLibIDPEntries{ LassoNode parent; /* <xs:element ref="IDPEntry" maxOccurs="unbounded"/> */ - LassoLibIDPEntry *IDPEntry; /* XXX: should actually be a GList */ + GList *IDPEntry; }; struct _LassoLibIDPEntriesClass { diff --git a/lasso/xml/lib_logout_request.c b/lasso/xml/lib_logout_request.c index c7b5af05..afd12201 100644 --- a/lasso/xml/lib_logout_request.c +++ b/lasso/xml/lib_logout_request.c @@ -70,81 +70,39 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0} }; +static struct QuerySnippet query_snippets[] = { + { "RequestID", NULL }, + { "MajorVersion", NULL }, + { "MinorVersion", NULL }, + { "IssueInstant", NULL }, + { "ProviderID", NULL }, + { "NameIdentifier/NameQualifier", "NameQualifier" }, + { "NameIdentifier/Format", "NameFormat" }, + { "NameIdentifier/content", "NameIdentifier" }, + { "SessionIndex", NULL }, + { "RelayState", NULL }, + { "consent", NULL }, + { NULL, NULL } +}; + + static LassoNodeClass *parent_class = NULL; static gchar* build_query(LassoNode *node) { - char *str, *t; - GString *s; - LassoLibLogoutRequest *request = LASSO_LIB_LOGOUT_REQUEST(node); - - str = parent_class->build_query(node); - s = g_string_new(str); - g_free(str); - - if (request->ProviderID) { - t = xmlURIEscapeStr(request->ProviderID, NULL); - g_string_append_printf(s, "&ProviderID=%s", t); - xmlFree(t); - } - if (request->NameIdentifier) { - t = lasso_node_build_query(LASSO_NODE(request->NameIdentifier)); - g_string_append_printf(s, "&%s", t); - g_free(t); - } - if (request->SessionIndex) - g_string_append_printf(s, "&SessionIndex=%s", request->SessionIndex); - if (request->RelayState) - g_string_append_printf(s, "&RelayState=%s", request->RelayState); - if (request->consent) - g_string_append_printf(s, "&consent=%s", request->consent); - - str = s->str; - g_string_free(s, FALSE); - - return str; + return lasso_node_build_query_from_snippets(node); } static gboolean init_from_query(LassoNode *node, char **query_fields) { LassoLibLogoutRequest *request = LASSO_LIB_LOGOUT_REQUEST(node); - int i; - char *t; request->NameIdentifier = lasso_saml_name_identifier_new(); + + lasso_node_init_from_query_fields(node, query_fields); - for (i=0; (t=query_fields[i]); i++) { - if (g_str_has_prefix(t, "ProviderID=")) { - request->ProviderID = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "SessionIndex=")) { - request->SessionIndex = g_strdup(t+16); - continue; - } - if (g_str_has_prefix(t, "RelayState=")) { - request->RelayState = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "consent=")) { - request->consent = g_strdup(t+8); - continue; - } - if (g_str_has_prefix(t, "NameIdentifier=")) { - request->NameIdentifier->content = g_strdup(t+15); - continue; - } - if (g_str_has_prefix(t, "NameFormat=")) { - request->NameIdentifier->Format = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "NameQualifier=")) { - request->NameIdentifier->NameQualifier = g_strdup(t+14); - continue; - } - } if (request->ProviderID == NULL || request->NameIdentifier->content == NULL || request->NameIdentifier->Format == NULL || @@ -154,7 +112,7 @@ init_from_query(LassoNode *node, char **query_fields) return FALSE; } - return parent_class->init_from_query(node, query_fields); + return TRUE; } /*****************************************************************************/ @@ -183,6 +141,7 @@ class_init(LassoLibLogoutRequestClass *klass) lasso_node_class_set_nodename(nclass, "LogoutRequest"); lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX); lasso_node_class_add_snippets(nclass, schema_snippets); + lasso_node_class_add_query_snippets(nclass, query_snippets); } GType diff --git a/lasso/xml/lib_register_name_identifier_request.c b/lasso/xml/lib_register_name_identifier_request.c index e792fadd..3825fa2a 100644 --- a/lasso/xml/lib_register_name_identifier_request.c +++ b/lasso/xml/lib_register_name_identifier_request.c @@ -95,7 +95,7 @@ static struct QuerySnippet query_snippets[] = { { "OldProvidedNameIdentifier/Format", "OldNameFormat"}, { "OldProvidedNameIdentifier/content", "OldProvidedNameIdentifier"}, { "RelayState", NULL }, - { NULL } + { NULL, NULL } }; static LassoNodeClass *parent_class = NULL; diff --git a/lasso/xml/lib_status_response.c b/lasso/xml/lib_status_response.c index 2861b26b..719e1ecb 100644 --- a/lasso/xml/lib_status_response.c +++ b/lasso/xml/lib_status_response.c @@ -66,69 +66,37 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0} }; +static struct QuerySnippet query_snippets[] = { + { "ResponseID", NULL }, + { "MajorVersion", NULL }, + { "MinorVersion", NULL }, + { "IssueInstant", NULL }, + { "Recipient", NULL }, + { "ProviderID", NULL }, + { "Status", "Value" }, + { "RelayState", NULL }, + { NULL, NULL } +}; + static LassoNodeClass *parent_class = NULL; static gchar* build_query(LassoNode *node) { - char *str, *t; - GString *s; - LassoLibStatusResponse *response = LASSO_LIB_STATUS_RESPONSE(node); - - str = parent_class->build_query(node); - s = g_string_new(str); - g_free(str); - - if (response->ProviderID) { - t = xmlURIEscapeStr(response->ProviderID, NULL); - g_string_append_printf(s, "&ProviderID=%s", t); - xmlFree(t); - } - if (response->RelayState) { - t = xmlURIEscapeStr(response->RelayState, NULL); - g_string_append_printf(s, "&RelayState=%s", t); - xmlFree(t); - } - if (response->Status) { - t = xmlURIEscapeStr(response->Status->StatusCode->Value, NULL); - g_string_append_printf(s, "&Value=%s", t); - xmlFree(t); - } - - str = s->str; - g_string_free(s, FALSE); - - return str; + return lasso_node_build_query_from_snippets(node); } static gboolean init_from_query(LassoNode *node, char **query_fields) { LassoLibStatusResponse *response = LASSO_LIB_STATUS_RESPONSE(node); - int i; - char *t; - - for (i=0; (t=query_fields[i]); i++) { - if (g_str_has_prefix(t, "ProviderID=")) { - response->ProviderID = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "RelayState=")) { - response->RelayState = g_strdup(t+11); - continue; - } - if (g_str_has_prefix(t, "Value=")) { - response->Status = lasso_samlp_status_new(); - response->Status->StatusCode = lasso_samlp_status_code_new(); - response->Status->StatusCode->Value = g_strdup(t+6); - continue; - } - } + response->Status = lasso_samlp_status_new(); + lasso_node_init_from_query_fields(node, query_fields); if (response->ProviderID == NULL || response->Status == NULL) return FALSE; - return parent_class->init_from_query(node, query_fields); + return TRUE; } @@ -157,6 +125,7 @@ class_init(LassoLibStatusResponseClass *klass) lasso_node_class_set_nodename(nclass, "StatusResponse"); lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX); lasso_node_class_add_snippets(nclass, schema_snippets); + lasso_node_class_add_query_snippets(nclass, query_snippets); } GType diff --git a/lasso/xml/saml_name_identifier.c b/lasso/xml/saml_name_identifier.c index 2599f3a0..77f1186e 100644 --- a/lasso/xml/saml_name_identifier.c +++ b/lasso/xml/saml_name_identifier.c @@ -41,41 +41,6 @@ */ /*****************************************************************************/ -/* public methods */ -/*****************************************************************************/ - -gchar* -lasso_saml_name_identifier_build_query(LassoSamlNameIdentifier *identifier, - char *prefix, char *prefix_content) -{ - GString *s; - char *str; - xmlChar *t; - - s = g_string_new(""); - if (identifier->NameQualifier) { - t = xmlURIEscapeStr(identifier->NameQualifier, NULL); - g_string_append_printf(s, "&%sNameQualifier=%s", prefix, t); - xmlFree(t); - } - if (identifier->Format) { - t = xmlURIEscapeStr(identifier->Format, NULL); - g_string_append_printf(s, "&%sNameFormat=%s", prefix, t); - xmlFree(t); - } - if (identifier->content) { - t = xmlURIEscapeStr(identifier->content, NULL); - g_string_append_printf(s, "&%sNameIdentifier=%s", prefix_content, t); - xmlFree(t); - } - - str = s->str; - g_string_free(s, FALSE); - - return str; -} - -/*****************************************************************************/ /* private methods */ /*****************************************************************************/ @@ -87,12 +52,6 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0 } }; -static gchar* -build_query(LassoNode *node) -{ - return lasso_saml_name_identifier_build_query(LASSO_SAML_NAME_IDENTIFIER(node), "", ""); -} - /*****************************************************************************/ /* instance and class init functions */ /*****************************************************************************/ @@ -110,7 +69,6 @@ class_init(LassoSamlNameIdentifierClass *klass) { LassoNodeClass *nclass = LASSO_NODE_CLASS(klass); - LASSO_NODE_CLASS(klass)->build_query = build_query; nclass->node_data = g_new0(LassoNodeClassData, 1); lasso_node_class_set_nodename(nclass, "NameIdentifier"); lasso_node_class_set_ns(nclass, LASSO_SAML_ASSERTION_HREF, LASSO_SAML_ASSERTION_PREFIX); diff --git a/lasso/xml/saml_name_identifier.h b/lasso/xml/saml_name_identifier.h index 287b3e63..709650f8 100644 --- a/lasso/xml/saml_name_identifier.h +++ b/lasso/xml/saml_name_identifier.h @@ -66,9 +66,6 @@ LASSO_EXPORT LassoSamlNameIdentifier* lasso_saml_name_identifier_new(void); LASSO_EXPORT LassoSamlNameIdentifier* lasso_saml_name_identifier_new_from_xmlNode(xmlNode*); -LASSO_EXPORT char* lasso_saml_name_identifier_build_query( - LassoSamlNameIdentifier *identifier, char *prefix, char *prefix_content); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lasso/xml/samlp_request_abstract.c b/lasso/xml/samlp_request_abstract.c index e250376f..188b4340 100644 --- a/lasso/xml/samlp_request_abstract.c +++ b/lasso/xml/samlp_request_abstract.c @@ -67,20 +67,6 @@ static struct XmlSnippet schema_snippets[] = { static LassoNodeClass *parent_class = NULL; -static gchar* -build_query(LassoNode *node) -{ - char *str; - - str = g_strdup_printf("RequestID=%s&MajorVersion=%d&MinorVersion=%d&IssueInstant=%s", - LASSO_SAMLP_REQUEST_ABSTRACT(node)->RequestID, - LASSO_SAMLP_REQUEST_ABSTRACT(node)->MajorVersion, - LASSO_SAMLP_REQUEST_ABSTRACT(node)->MinorVersion, - LASSO_SAMLP_REQUEST_ABSTRACT(node)->IssueInstant); - return str; -} - - static xmlNode* get_xmlNode(LassoNode *node) { @@ -125,39 +111,6 @@ get_xmlNode(LassoNode *node) return xmlnode; } -static gboolean -init_from_query(LassoNode *node, char **query_fields) -{ - LassoSamlpRequestAbstract *request = LASSO_SAMLP_REQUEST_ABSTRACT(node); - int i; - char *t; - - for (i=0; (t=query_fields[i]); i++) { - if (strncmp(t, "RequestID=", 10) == 0) { - request->RequestID = g_strdup(t+10); - continue; - } - if (strncmp(t, "MajorVersion=", 13) == 0) { - request->MajorVersion = atoi(t+13); - continue; - } - if (strncmp(t, "MinorVersion=", 13) == 0) { - request->MinorVersion = atoi(t+13); - continue; - } - if (strncmp(t, "IssueInstant=", 13) == 0) { - request->IssueInstant = g_strdup(t+13); - continue; - } - } - - if (request->RequestID == NULL || request->IssueInstant == NULL || - request->MajorVersion == 0) - return FALSE; - - return TRUE; -} - static char* get_sign_attr_name() { @@ -186,9 +139,7 @@ class_init(LassoSamlpRequestAbstractClass *klass) LassoNodeClass *nclass = LASSO_NODE_CLASS(klass); parent_class = g_type_class_peek_parent(klass); - nclass->build_query = build_query; nclass->get_xmlNode = get_xmlNode; - nclass->init_from_query = init_from_query; nclass->get_sign_attr_name = get_sign_attr_name; nclass->node_data = g_new0(LassoNodeClassData, 1); lasso_node_class_set_nodename(nclass, "RequestAbstract"); diff --git a/lasso/xml/samlp_response_abstract.c b/lasso/xml/samlp_response_abstract.c index bdc4d57c..128054fa 100644 --- a/lasso/xml/samlp_response_abstract.c +++ b/lasso/xml/samlp_response_abstract.c @@ -73,21 +73,6 @@ static struct XmlSnippet schema_snippets[] = { static LassoNodeClass *parent_class = NULL; -static gchar* -build_query(LassoNode *node) -{ - char *str; - - str = g_strdup_printf("ResponseID=%s&MajorVersion=%d&MinorVersion=%d&IssueInstant=%s", - LASSO_SAMLP_RESPONSE_ABSTRACT(node)->ResponseID, - LASSO_SAMLP_RESPONSE_ABSTRACT(node)->MajorVersion, - LASSO_SAMLP_RESPONSE_ABSTRACT(node)->MinorVersion, - LASSO_SAMLP_RESPONSE_ABSTRACT(node)->IssueInstant); - /* XXX: & Recipient & InResponseTo*/ - return str; -} - - static xmlNode* get_xmlNode(LassoNode *node) { @@ -133,47 +118,6 @@ get_xmlNode(LassoNode *node) return xmlnode; } -static gboolean -init_from_query(LassoNode *node, char **query_fields) -{ - LassoSamlpResponseAbstract *response = LASSO_SAMLP_RESPONSE_ABSTRACT(node); - int i; - char *t; - - for (i=0; (t=query_fields[i]); i++) { - if (strncmp(t, "ResponseID=", 10) == 0) { - response->ResponseID = g_strdup(t+10); - continue; - } - if (strncmp(t, "MajorVersion=", 13) == 0) { - response->MajorVersion = atoi(t+13); - continue; - } - if (strncmp(t, "MinorVersion=", 13) == 0) { - response->MinorVersion = atoi(t+13); - continue; - } - if (strncmp(t, "IssueInstant=", 13) == 0) { - response->IssueInstant = g_strdup(t+13); - continue; - } - if (strncmp(t, "Recipient=", 9) == 0) { - response->Recipient = g_strdup(t+9); - continue; - } - if (strncmp(t, "InResponseTo=", 13) == 0) { - response->InResponseTo = g_strdup(t+13); - continue; - } - } - - if (response->ResponseID == NULL || response->IssueInstant == NULL || - response->MajorVersion == 0) - return FALSE; - - return TRUE; -} - static char* get_sign_attr_name() { @@ -205,8 +149,6 @@ class_init(LassoSamlpResponseAbstractClass *klass) parent_class = g_type_class_peek_parent(klass); nclass->get_xmlNode = get_xmlNode; - nclass->build_query = build_query; - nclass->init_from_query = init_from_query; nclass->get_sign_attr_name = get_sign_attr_name; nclass->node_data = g_new0(LassoNodeClassData, 1); lasso_node_class_set_nodename(nclass, "ResponseAbstract"); diff --git a/lasso/xml/samlp_status.c b/lasso/xml/samlp_status.c index 4f3b5fae..a9649d6f 100644 --- a/lasso/xml/samlp_status.c +++ b/lasso/xml/samlp_status.c @@ -50,11 +50,52 @@ static struct XmlSnippet schema_snippets[] = { { NULL, 0, 0} }; +static gchar* +build_query(LassoNode *node) +{ + LassoSamlpStatusCode *code = LASSO_SAMLP_STATUS(node)->StatusCode; + GString *s; + char *t; + + s = g_string_sized_new(200); + while (code) { + if (s->len) + g_string_append(s, " "); + g_string_append(s, code->Value); + code = code->StatusCode; + } + + t = s->str; + g_string_free(s, FALSE); + return t; +} + +static gboolean +init_from_query(LassoNode *node, char **query_fields) +{ + char **values; + LassoSamlpStatusCode *code; + int i; + + code = lasso_samlp_status_code_new(); + LASSO_SAMLP_STATUS(node)->StatusCode = code; + values = g_strsplit(*query_fields, " ", 0); + for (i = 0; values[i]; i++) { + code->Value = g_strdup(values[i]); + if (values[i+1]) { + code->StatusCode = lasso_samlp_status_code_new(); + code = code->StatusCode; + } + } + + g_strfreev(values); + return TRUE; +} + /*****************************************************************************/ /* instance and class init functions */ /*****************************************************************************/ - static void instance_init(LassoSamlpStatus *node) { @@ -67,6 +108,8 @@ class_init(LassoSamlpStatusClass *klass) { LassoNodeClass *nclass = LASSO_NODE_CLASS(klass); + nclass->build_query = build_query; + nclass->init_from_query = init_from_query; nclass->node_data = g_new0(LassoNodeClassData, 1); lasso_node_class_set_nodename(nclass, "Status"); lasso_node_class_set_ns(nclass, LASSO_SAML_PROTOCOL_HREF, LASSO_SAML_PROTOCOL_PREFIX); diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index 87487a37..2e42d453 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -1115,9 +1115,9 @@ find_xml_snippet_by_name(LassoNode *node, char *name) class = LASSO_NODE_GET_CLASS(node); while (class && LASSO_IS_NODE_CLASS(class) && class->node_data) { for (snippet = class->node_data->snippets; - snippet->name && strcmp(snippet->name, name) != 0; + snippet && snippet->name && strcmp(snippet->name, name) != 0; snippet++) ; - if (snippet->name) + if (snippet && snippet->name) return snippet; class = g_type_class_peek_parent(class); } @@ -1145,6 +1145,9 @@ find_path(LassoNode *node, char *path, LassoNode **value_node, struct XmlSnippet s = t+1; } + if (tsnippet == NULL) + return -1; + *snippet = tsnippet; *value_node = tnode; return 0; @@ -1156,7 +1159,6 @@ get_value_by_path(LassoNode *node, char *path) { struct XmlSnippet *snippet; LassoNode *value_node; - void *value; if (find_path(node, path, &value_node, &snippet) != 0) return NULL; @@ -1167,8 +1169,11 @@ get_value_by_path(LassoNode *node, char *path) } else if (snippet->type & SNIPPET_INTEGER) { int v = G_STRUCT_MEMBER(int, value_node, snippet->offset); return g_strdup_printf("%d", v); + } else if (snippet->type == SNIPPET_NODE) { + LassoNode *value = G_STRUCT_MEMBER(LassoNode*, value_node, snippet->offset); + return lasso_node_build_query(value); } else { - value = G_STRUCT_MEMBER(char*, value_node, snippet->offset); + char *value = G_STRUCT_MEMBER(char*, value_node, snippet->offset); if (value == NULL) return NULL; return g_strdup(value); } @@ -1193,6 +1198,13 @@ set_value_at_path(LassoNode *node, char *path, char *query_value) } else if (snippet->type & SNIPPET_BOOLEAN) { int val = (strcmp(query_value, "true") == 0); (*(int*)value) = val; + } else if (snippet->type == SNIPPET_NODE) { + LassoNode *v = *(LassoNode**)value; + if (v == NULL) { + message(G_LOG_LEVEL_CRITICAL, "building node from query; unknown subnode"); + g_assert_not_reached(); + } + LASSO_NODE_GET_CLASS(v)->init_from_query(v, &query_value); } else { (*(char**)value) = g_strdup(query_value); } @@ -1210,16 +1222,21 @@ lasso_node_build_query_from_snippets(LassoNode *node) GString *s; xmlChar *t; LassoNodeClass *class = LASSO_NODE_GET_CLASS(node); - struct QuerySnippet *query_snippets; + struct QuerySnippet *query_snippets = NULL; - query_snippets = class->node_data->query_snippets; + while (class && LASSO_IS_NODE_CLASS(class) && class->node_data) { + if (class->node_data && class->node_data->query_snippets) { + query_snippets = class->node_data->query_snippets; + break; + } + class = g_type_class_peek_parent(class); + } + if (query_snippets == NULL) + return NULL; s = g_string_sized_new(2000); for (i=0; query_snippets[i].path; i++) { -#if 0 - fprintf(stderr, "getting value at %s\n", query_snippets[i].path); -#endif memset(path, 0, 100); strncpy(path, query_snippets[i].path, 100); v = get_value_by_path(node, path); @@ -1244,15 +1261,23 @@ lasso_node_build_query_from_snippets(LassoNode *node) } -void +gboolean lasso_node_init_from_query_fields(LassoNode *node, char **query_fields) { int i, j; char *field, *t; LassoNodeClass *class = LASSO_NODE_GET_CLASS(node); - struct QuerySnippet *query_snippets; + struct QuerySnippet *query_snippets = NULL; - query_snippets = class->node_data->query_snippets; + while (class && LASSO_IS_NODE_CLASS(class) && class->node_data) { + if (class->node_data && class->node_data->query_snippets) { + query_snippets = class->node_data->query_snippets; + break; + } + class = g_type_class_peek_parent(class); + } + if (query_snippets == NULL) + return FALSE; for (i=0; (field=query_fields[i]); i++) { t = strchr(field, '='); @@ -1277,5 +1302,6 @@ lasso_node_init_from_query_fields(LassoNode *node, char **query_fields) *t = '='; } + return TRUE; } |