[xml] rewrite schema directed serialization/deserialization methods

The new implementations of lasso_node_impl_init_from_xml now validate
namespace of all child nodes befores parsing. It stops on any error. For
node which implement their own parsing of an attribute or a node, it
must declare an XmlSnippet with an offset field set to 0. The 0 value is
invalid for public GObject structure (it's the place of the GObject
machinery like the reference count). The 0 offset can be used for
XmlSnippet in a private structure, so never set the offset to 0 with the
flag SNIPPET_PRIVATE, for a field which is parsed by you get_xmlNode
virtual method.

Other ameliorations in this commit is the possibility to set attributes
with namespace when using the flags SNIPPET_ATTRIBUTE|SNIPPET_ANY. The
syntax for an attribute is inspired by the element tree API from Python:

	{namespace}attribute_name

an example:

	{http://www.w3.org/2001/XMLSchema-instance}type

for the classic xsi:type attribute.
This commit is contained in:
Benjamin Dauvergne 2011-12-16 11:12:58 +01:00
parent 9a31985671
commit 154812b401
20 changed files with 674 additions and 570 deletions

View File

@ -456,6 +456,15 @@ lasso_defederation_validate_notification(LassoDefederation *defederation)
/* instance and class init functions */
/*****************************************************************************/
static void
class_init(LassoDefederationClass *klass)
{
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
nclass->node_data = NULL;
}
GType
lasso_defederation_get_type()
{
@ -464,11 +473,11 @@ lasso_defederation_get_type()
if (!this_type) {
static const GTypeInfo this_info = {
sizeof (LassoDefederationClass),
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, (GClassInitFunc) class_init, NULL, NULL,
sizeof(LassoDefederation),
0,
NULL,
NULL
NULL,
};
this_type = g_type_register_static(LASSO_TYPE_PROFILE,

View File

@ -167,6 +167,7 @@ static struct XmlSnippet schema_snippets[] = {
G_STRUCT_OFFSET(LassoFederation, remote_nameIdentifier), NULL, NULL, NULL},
{ "RemoteProviderID", SNIPPET_ATTRIBUTE,
G_STRUCT_OFFSET(LassoFederation, remote_providerID), NULL, NULL, NULL},
{ "FederationDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL },
{NULL, 0, 0, NULL, NULL, NULL}
};

View File

@ -274,6 +274,9 @@
#include "../id-wsf/id_ff_extensions_private.h"
#endif
#define LASSO_LOGIN_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), LASSO_TYPE_LOGIN, LassoLoginPrivate))
static void lasso_login_build_assertion_artifact(LassoLogin *login);
@ -2286,6 +2289,10 @@ static struct XmlSnippet schema_snippets[] = {
{ "AssertionArtifact", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoLogin, assertionArtifact), NULL, NULL, NULL},
{ "NameIDPolicy", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoLogin, nameIDPolicy), NULL, NULL, NULL},
{ "Assertion", SNIPPET_NODE_IN_CHILD, G_STRUCT_OFFSET(LassoLogin, assertion), NULL, NULL, NULL},
{ "RequestID", SNIPPET_CONTENT | SNIPPET_PRIVATE,
G_STRUCT_OFFSET(LassoLoginPrivate, request_id), NULL, NULL, NULL},
{ "LoginDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL},
{ "ProtocolProfile", SNIPPET_CONTENT, 0, NULL, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}
};
@ -2299,7 +2306,6 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump)
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
xmlSetProp(xmlnode, (xmlChar*)"LoginDumpVersion", (xmlChar*)"2");
xmlSetProp(xmlnode, (xmlChar*)"RequestID", (xmlChar*)LASSO_LOGIN(node)->private_data->request_id);
if (login->protocolProfile == LASSO_LOGIN_PROTOCOL_PROFILE_BRWS_ART)
xmlNewTextChild(xmlnode, NULL, (xmlChar*)"ProtocolProfile", (xmlChar*)"Artifact");
@ -2321,9 +2327,6 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode)
rc = parent_class->init_from_xml(node, xmlnode);
if (rc) return rc;
lasso_assign_new_string(LASSO_LOGIN(node)->private_data->request_id, (char*)xmlGetProp(xmlnode,
(xmlChar*)"RequestID"));
t = xmlnode->children;
while (t) {
if (t->type != XML_ELEMENT_NODE) {
@ -2367,14 +2370,6 @@ dispose(GObject *object)
G_OBJECT_CLASS(parent_class)->dispose(object);
}
static void
finalize(GObject *object)
{
LassoLogin *login = LASSO_LOGIN(object);
lasso_release(login->private_data);
G_OBJECT_CLASS(parent_class)->finalize(object);
}
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
@ -2382,8 +2377,7 @@ finalize(GObject *object)
static void
instance_init(LassoLogin *login)
{
login->private_data = g_new0(LassoLoginPrivate, 1);
login->private_data = LASSO_LOGIN_GET_PRIVATE(login);
login->protocolProfile = 0;
login->assertionArtifact = NULL;
login->nameIDPolicy = NULL;
@ -2402,9 +2396,9 @@ class_init(LassoLoginClass *klass)
lasso_node_class_set_nodename(nclass, "Login");
lasso_node_class_set_ns(nclass, LASSO_LASSO_HREF, LASSO_LASSO_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
g_type_class_add_private(klass, sizeof(LassoLoginPrivate));
G_OBJECT_CLASS(klass)->dispose = dispose;
G_OBJECT_CLASS(klass)->finalize = finalize;
}
GType

View File

@ -1162,6 +1162,7 @@ static struct XmlSnippet schema_snippets[] = {
G_STRUCT_OFFSET(LassoLogout, initial_remote_providerID), NULL, NULL, NULL},
{ "InitialHttpRequestMethod", SNIPPET_CONTENT | SNIPPET_INTEGER,
G_STRUCT_OFFSET(LassoLogout, initial_http_request_method), NULL, NULL, NULL},
{ "LogoutDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL },
/* "ProviderIdIndex" must not be dumped (since apps assume to get
* it back to 0 after a restore from dump) (maybe this behaviour should
* be fixed)

View File

@ -645,6 +645,7 @@ lasso_name_registration_validate_request(LassoNameRegistration *name_registratio
static struct XmlSnippet schema_snippets[] = {
{ "OldNameIdentifier", SNIPPET_NODE_IN_CHILD,
G_STRUCT_OFFSET(LassoNameRegistration, oldNameIdentifier), NULL, NULL, NULL},
{ "NameRegistrationDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}
};

View File

@ -539,69 +539,15 @@ static struct XmlSnippet schema_snippets[] = {
NULL, NULL},
{ "HttpRequestMethod", SNIPPET_CONTENT | SNIPPET_INTEGER,
G_STRUCT_OFFSET(LassoProfile, http_request_method), NULL, NULL, NULL},
{ "Artifact", SNIPPET_CONTENT | SNIPPET_PRIVATE, G_STRUCT_OFFSET(LassoProfilePrivate,
artifact), NULL, NULL, NULL },
{ "ArtifactMessage", SNIPPET_CONTENT | SNIPPET_PRIVATE, G_STRUCT_OFFSET(LassoProfilePrivate,
artifact_message), NULL, NULL, NULL },
{NULL, 0, 0, NULL, NULL, NULL}
};
static LassoNodeClass *parent_class = NULL;
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
xmlNode *xmlnode;
LassoProfile *profile = LASSO_PROFILE(node);
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
if (profile->private_data->artifact) {
xmlNewTextChild(xmlnode, NULL, (xmlChar*)"Artifact",
(xmlChar*)profile->private_data->artifact);
}
if (profile->private_data->artifact_message) {
xmlNewTextChild(xmlnode, NULL, (xmlChar*)"ArtifactMessage",
(xmlChar*)profile->private_data->artifact_message);
}
return xmlnode;
}
static int
init_from_xml(LassoNode *node, xmlNode *xmlnode)
{
LassoProfile *profile = LASSO_PROFILE(node);
xmlNode *t;
parent_class->init_from_xml(node, xmlnode);
if (xmlnode == NULL)
return LASSO_XML_ERROR_OBJECT_CONSTRUCTION_FAILED;
t = xmlnode->children;
while (t) {
xmlChar *s;
if (t->type != XML_ELEMENT_NODE) {
t = t->next;
continue;
}
if (strcmp((char*)t->name, "Artifact") == 0) {
s = xmlNodeGetContent(t);
lasso_assign_string(profile->private_data->artifact, (char*)s);
xmlFree(s);
} else if (strcmp((char*)t->name, "ArtifactMessage") == 0) {
s = xmlNodeGetContent(t);
lasso_assign_string(profile->private_data->artifact_message, (char*)s);
xmlFree(s);
}
t = t->next;
}
return 0;
}
/**
* lasso_profile_set_signature_hint:
* @profile: a #LassoProfile object
@ -819,14 +765,6 @@ dispose(GObject *object)
G_OBJECT_CLASS(parent_class)->dispose(G_OBJECT(profile));
}
static void
finalize(GObject *object)
{
LassoProfile *profile = LASSO_PROFILE(object);
lasso_release(profile->private_data);
G_OBJECT_CLASS(parent_class)->finalize(object);
}
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
@ -834,7 +772,7 @@ finalize(GObject *object)
static void
instance_init(LassoProfile *profile)
{
profile->private_data = g_new0(LassoProfilePrivate, 1);
profile->private_data = LASSO_PROFILE_GET_PRIVATE(profile);
profile->private_data->dispose_has_run = FALSE;
profile->private_data->artifact = NULL;
profile->private_data->artifact_message = NULL;
@ -864,11 +802,9 @@ class_init(LassoProfileClass *klass)
lasso_node_class_set_nodename(nclass, "Profile");
lasso_node_class_set_ns(nclass, LASSO_LASSO_HREF, LASSO_LASSO_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
nclass->get_xmlNode = get_xmlNode;
nclass->init_from_xml = init_from_xml;
g_type_class_add_private(klass, sizeof(LassoProfilePrivate));
G_OBJECT_CLASS(klass)->dispose = dispose;
G_OBJECT_CLASS(klass)->finalize = finalize;
}
GType

View File

@ -44,6 +44,9 @@ struct _LassoProfilePrivate
void lasso_profile_set_response_status(LassoProfile *profile, const gchar *statusCodeValue);
void lasso_profile_clean_msg_info(LassoProfile *profile);
#define LASSO_PROFILE_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), LASSO_TYPE_PROFILE, LassoProfilePrivate))
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -516,6 +516,9 @@ static struct XmlSnippet schema_snippets[] = {
{ "CaCertChainFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProvider, ca_cert_chain), NULL, NULL, NULL},
{ "MetadataFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoProvider, metadata_filename), NULL, NULL, NULL},
{ "ProviderID", SNIPPET_ATTRIBUTE, G_STRUCT_OFFSET(LassoProvider, ProviderID), NULL, NULL, NULL},
{ "ProviderRole", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL},
{ "EncryptionMode", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL},
{ "ProviderDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}
};

View File

@ -254,10 +254,20 @@ cleanup:
/*****************************************************************************/
static struct XmlSnippet schema_snippets[] = {
{ "PrivateKeyFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoServer, private_key), NULL, NULL, NULL},
{ "PrivateKeyFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoServer, private_key), NULL,
NULL, NULL},
{ "PrivateKeyPassword", SNIPPET_CONTENT,
G_STRUCT_OFFSET(LassoServer, private_key_password), NULL, NULL, NULL},
{ "CertificateFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoServer, certificate), NULL, NULL, NULL},
{ "CertificateFilePath", SNIPPET_CONTENT, G_STRUCT_OFFSET(LassoServer, certificate), NULL,
NULL, NULL},
{ "SignatureMethod", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL },
{ "Providers", SNIPPET_LIST_NODES, 0, NULL, NULL, NULL },
{ "ServerDumpVersion", SNIPPET_ATTRIBUTE, 0, NULL, NULL, NULL },
#ifdef LASSO_WSF_ENABLED
{ "Services", SNIPPET_LIST_NODES, 0, NULL, NULL, NULL },
{ "SvcMDs", SNIPPET_LIST_NODES, 0, NULL, NULL, NULL },
#endif
{NULL, 0, 0, NULL, NULL, NULL}
};

View File

@ -79,7 +79,8 @@ class_init(LassoLibAssertionClass *klass)
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
lasso_node_class_set_nodename(nclass, "Assertion");
nclass->node_data->xsi_sub_type = TRUE;
lasso_node_class_set_nodename(nclass, "AssertionType");
lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
}

View File

@ -74,7 +74,8 @@ class_init(LassoLibAuthenticationStatementClass *klass)
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
lasso_node_class_set_nodename(nclass, "AuthenticationStatement");
nclass->node_data->xsi_sub_type = TRUE;
lasso_node_class_set_nodename(nclass, "AuthenticationStatementType");
lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
}

View File

@ -67,7 +67,8 @@ class_init(LassoLibSubjectClass *klass)
LassoNodeClass *nclass = LASSO_NODE_CLASS(klass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
lasso_node_class_set_nodename(nclass, "Subject");
nclass->node_data->xsi_sub_type = TRUE;
lasso_node_class_set_nodename(nclass, "SubjectType");
lasso_node_class_set_ns(nclass, LASSO_LIB_HREF, LASSO_LIB_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
}

View File

@ -33,6 +33,7 @@
typedef struct {
xmlNode *xml_content;
GHashTable *any_attributes;
} LassoMiscTextNodePrivate;
#define LASSO_MISC_TEXT_NODE_GET_PRIVATE(o) \
@ -41,30 +42,19 @@ typedef struct {
static struct XmlSnippet schema_snippets[] = {
{ "content", SNIPPET_TEXT_CHILD,
G_STRUCT_OFFSET(LassoMiscTextNode, content), NULL, NULL, NULL},
{ "any_attributes", SNIPPET_ATTRIBUTE | SNIPPET_ANY | SNIPPET_PRIVATE,
G_STRUCT_OFFSET(LassoMiscTextNodePrivate, any_attributes), NULL, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}
};
static LassoNodeClass *parent_class = NULL;
static void
insure_namespace(xmlNode *xmlnode, xmlNs *ns)
{
xmlNode *t = xmlnode->children;
xmlSetNs(xmlnode, ns);
while (t) {
if (t->type == XML_ELEMENT_NODE && t->ns == NULL)
insure_namespace(t, ns);
t = t->next;
}
}
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
{
xmlNode *xmlnode;
xmlNs *ns;
LassoMiscTextNode *mtnode = (LassoMiscTextNode*)node;
LassoMiscTextNodePrivate *private;
private = LASSO_MISC_TEXT_NODE_GET_PRIVATE(node);
@ -77,10 +67,12 @@ get_xmlNode(LassoNode *node, gboolean lasso_dump)
}
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
xmlNodeSetName(xmlnode, (xmlChar*)LASSO_MISC_TEXT_NODE(node)->name);
ns = xmlNewNs(xmlnode, (xmlChar*)LASSO_MISC_TEXT_NODE(node)->ns_href,
(xmlChar*)LASSO_MISC_TEXT_NODE(node)->ns_prefix);
insure_namespace(xmlnode, ns);
xmlNodeSetName(xmlnode, BAD_CAST mtnode->name);
if (! lasso_strisempty(mtnode->ns_href) && ! lasso_strisempty(mtnode->ns_href)) {
ns = xmlNewNs(xmlnode, BAD_CAST mtnode->ns_href,
BAD_CAST mtnode->ns_prefix);
xmlSetNs(xmlnode, ns);
}
return xmlnode;
}

View File

@ -40,7 +40,7 @@ typedef enum {
SNIPPET_NODE,
SNIPPET_CONTENT,
SNIPPET_TEXT_CHILD,
SNIPPET_NAME_IDENTIFIER,
SNIPPET_UNUSED1,
SNIPPET_ATTRIBUTE,
SNIPPET_NODE_IN_CHILD,
SNIPPET_LIST_NODES,
@ -72,11 +72,15 @@ typedef enum {
} SignatureVerificationOption;
struct XmlSnippet {
char *name;
SnippetType type;
guint offset;
char *class_name;
char *ns_name;
char *name; /* name of the node or attribute to match */
SnippetType type; /* type of node to deserialize */
guint offset; /* offset of the storage field relative to the public or private object (if
using SNIPPET_PRIVATE). If 0, means that no storage must be done, it will
be handled by the init_from_xml virtual method. */
char *class_name; /* Force a certain LassoNode class for deserializing a node, usually
useless. */
char *ns_name; /* if the namespace is different from the one of the parent node, specify it
there */
char *ns_uri;
};
@ -156,6 +160,7 @@ struct _LassoNodeClassData
int private_key_file_offset;
int certificate_file_offset;
gboolean keep_xmlnode;
gboolean xsi_sub_type;
};
void lasso_node_class_set_nodename(LassoNodeClass *klass, char *name);
@ -278,6 +283,22 @@ LassoSignatureContext lasso_make_signature_context_from_path_or_string(char *fil
const char *password, LassoSignatureMethod signature_method,
const char *certificate);
xmlNs * get_or_define_ns(xmlNode *xmlnode, const xmlChar *ns_uri, const xmlChar
*advised_prefix);
void set_qname_attribute(xmlNode *node,
const xmlChar *attribute_ns_prefix,
const xmlChar *attribute_ns_href,
const xmlChar *attribute_name,
const xmlChar *prefix,
const xmlChar *href,
const xmlChar *name);
void set_xsi_type(xmlNode *node,
const xmlChar *type_ns_prefix,
const xmlChar *type_ns_href,
const xmlChar *type_name);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -58,68 +58,33 @@
/* private methods */
/*****************************************************************************/
struct _LassoSaml2KeyInfoConfirmationDataTypePrivate {
GList *KeyInfo;
};
static struct XmlSnippet schema_snippets[] = {
{ "KeyInfo", SNIPPET_LIST_NODES,
G_STRUCT_OFFSET(LassoSaml2KeyInfoConfirmationDataType, KeyInfo), NULL, NULL, NULL},
{ "KeyInfo", SNIPPET_LIST_NODES|SNIPPET_PRIVATE,
G_STRUCT_OFFSET(LassoSaml2KeyInfoConfirmationDataTypePrivate, KeyInfo), "LassoDsKeyInfo", NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}
};
static LassoNodeClass *parent_class = NULL;
#define LASSO_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), LASSO_TYPE_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE, LassoSaml2KeyInfoConfirmationDataTypePrivate))
/*****************************************************************************/
/* instance and class init functions */
/*****************************************************************************/
static xmlNs *
ensure_namespace(xmlNode *node, const xmlChar *href, const xmlChar *prefix)
{
xmlNs *ns;
ns = xmlSearchNsByHref(node->doc, node, href);
if (! ns) {
ns = xmlNewNs(node, href, prefix);
xmlSetNs(node, ns);
}
return ns;
}
static void
set_qname_attribue(xmlNode *node, xmlChar *attribute_name, const xmlChar *name, const
xmlChar *href, const xmlChar *prefix) {
xmlNs *type_ns;
xmlNs *xsi_ns;
xmlChar *value;
xsi_ns = ensure_namespace(node, BAD_CAST LASSO_XSI_HREF, BAD_CAST LASSO_XSI_PREFIX);
type_ns = ensure_namespace(node, href, prefix);
value = BAD_CAST g_strdup_printf("%s:%s", type_ns->prefix, name);
xmlSetNsProp(node, xsi_ns, attribute_name, value);
lasso_release_string(value);
}
static void
set_xsi_type(xmlNode *node, const xmlChar *type, const xmlChar *href, const xmlChar *prefix) {
set_qname_attribue(node, BAD_CAST "type", type, href, prefix);
}
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump)
instance_init(LassoSaml2KeyInfoConfirmationDataType *saml2_key_info_confirmation_data_type)
{
xmlNode *xmlnode = NULL;
/* add xsi:type="KeyInfoConfirmationDataType" */
xmlnode = parent_class->get_xmlNode(node, lasso_dump);
set_xsi_type(xmlnode,
BAD_CAST "KeyInfoConfirmationDataType",
BAD_CAST LASSO_SAML2_ASSERTION_HREF,
BAD_CAST LASSO_SAML2_ASSERTION_PREFIX);
return xmlnode;
saml2_key_info_confirmation_data_type->private_data =
LASSO_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE_GET_PRIVATE(
saml2_key_info_confirmation_data_type);
}
static void
class_init(LassoSaml2KeyInfoConfirmationDataTypeClass *klass)
{
@ -127,8 +92,11 @@ class_init(LassoSaml2KeyInfoConfirmationDataTypeClass *klass)
parent_class = g_type_class_peek_parent(klass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
nclass->get_xmlNode = get_xmlNode;
nclass->node_data->xsi_sub_type = TRUE;
lasso_node_class_set_nodename(nclass, "KeyInfoConfirmationDataType");
lasso_node_class_set_ns(nclass, LASSO_SAML2_ASSERTION_HREF, LASSO_SAML2_ASSERTION_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
g_type_class_add_private(klass, sizeof(LassoSaml2KeyInfoConfirmationDataTypePrivate));
}
GType
@ -146,7 +114,7 @@ lasso_saml2_key_info_confirmation_data_type_get_type()
NULL,
sizeof(LassoSaml2KeyInfoConfirmationDataType),
0,
NULL,
(GInstanceInitFunc)instance_init,
NULL
};
@ -171,3 +139,41 @@ lasso_saml2_key_info_confirmation_data_type_new()
{
return g_object_new(LASSO_TYPE_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE, NULL);
}
/**
* lasso_saml2_key_info_confirmation_data_type_get_key_info:
* @kicdt: a #LassoSaml2KeyInfoConfirmationDataType object.
*
* Return the list of KeyInfo node contained in the saml2:SubjectConfirmationData of type
* saml2:KeyInfoConfirmationDataType.
*
* Return value:(element-type LassoDsKeyInfo)(transfer none): a list of #LassoDsKeyInfo objects.
*/
GList*
lasso_saml2_key_info_confirmation_data_type_get_key_info(
LassoSaml2KeyInfoConfirmationDataType *kicdt)
{
lasso_return_val_if_fail(LASSO_IS_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE(kicdt), NULL);
return kicdt->private_data->KeyInfo;
}
/**
* lasso_saml2_key_info_confirmation_data_type_set_key_info:
* @kicdt: a #LassoSaml2KeyInfoConfirmationDataType object.
* @key_infos:(tranfer none)(element-type LassoDsKeyInfo): a list of #LassoDsKeyInfo object.
*
* Set the list of ds:KeyInfo nodes for the saml2:SubjectConfirmationData of type
* saml2:KeyInfoConfirmationDataType.
*/
void
lasso_saml2_key_info_confirmation_data_type_set_key_info(
LassoSaml2KeyInfoConfirmationDataType *kicdt,
GList *key_infos)
{
lasso_return_if_fail(LASSO_IS_SAML2_KEY_INFO_CONFIRMATION_DATA_TYPE(kicdt));
lasso_assign_list_of_gobjects(
kicdt->private_data->KeyInfo,
key_infos);
}

View File

@ -51,14 +51,13 @@ extern "C" {
typedef struct _LassoSaml2KeyInfoConfirmationDataType LassoSaml2KeyInfoConfirmationDataType;
typedef struct _LassoSaml2KeyInfoConfirmationDataTypeClass LassoSaml2KeyInfoConfirmationDataTypeClass;
typedef struct _LassoSaml2KeyInfoConfirmationDataTypePrivate LassoSaml2KeyInfoConfirmationDataTypePrivate;
struct _LassoSaml2KeyInfoConfirmationDataType {
LassoSaml2SubjectConfirmationData parent;
/*< public >*/
/* attributes */
GList *KeyInfo; /* of LassoDsKeyInfo */
/*< private >*/
LassoSaml2KeyInfoConfirmationDataTypePrivate *private_data;
};
@ -68,8 +67,11 @@ struct _LassoSaml2KeyInfoConfirmationDataTypeClass {
LASSO_EXPORT GType lasso_saml2_key_info_confirmation_data_type_get_type(void);
LASSO_EXPORT LassoNode* lasso_saml2_key_info_confirmation_data_type_new(void);
LASSO_EXPORT GList *lasso_saml2_key_info_confirmation_data_type_get_key_info(
LassoSaml2KeyInfoConfirmationDataType *kicdt);
LASSO_EXPORT void lasso_saml2_key_info_confirmation_data_type_set_key_info(
LassoSaml2KeyInfoConfirmationDataType *kicdt,
GList *key_infos);
#ifdef __cplusplus
}

View File

@ -142,7 +142,6 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode)
rc = parent_class->init_from_xml(node, xmlnode);
if (rc == 0) {
GList *last;
pv = GET_PRIVATE(node);
child = xmlSecFindChild(xmlnode, BAD_CAST SESSION_INDEX,
@ -154,11 +153,10 @@ init_from_xml(LassoNode *node, xmlNode *xmlnode)
lasso_release_xml_string(content);
child = xmlSecGetNextElementNode(child->next);
}
/* remove the last one, since it is also stored in node->SessionIndex */
last = g_list_last(pv->SessionIndex);
if (last) {
lasso_release_string(last->data);
pv->SessionIndex = g_list_delete_link(pv->SessionIndex, last);
/* remove the first one, since it is also stored in node->SessionIndex */
if (pv->SessionIndex) {
lasso_release_string(pv->SessionIndex->data);
pv->SessionIndex = g_list_delete_link(pv->SessionIndex, pv->SessionIndex);
}
}

View File

@ -65,9 +65,6 @@ static struct XmlSnippet schema_snippets[] = {
/* instance and class init functions */
/*****************************************************************************/
static xmlNode* get_xmlNode(LassoNode *node, gboolean lasso_dump);
static LassoNodeClass *parent_class = NULL;
static void
@ -77,28 +74,11 @@ class_init(LassoSoapBodyClass *klass)
parent_class = g_type_class_peek_parent(nclass);
nclass->node_data = g_new0(LassoNodeClassData, 1);
nclass->get_xmlNode = get_xmlNode;
lasso_node_class_set_nodename(nclass, "Body");
lasso_node_class_set_ns(nclass, LASSO_SOAP_ENV_HREF, LASSO_SOAP_ENV_PREFIX);
lasso_node_class_add_snippets(nclass, schema_snippets);
}
static xmlNode*
get_xmlNode(LassoNode *node, gboolean lasso_dump) {
xmlNodePtr ret;
/* Fix namespace of Id */
ret = parent_class->get_xmlNode(node, lasso_dump);
{
xmlNsPtr ns;
ns = xmlNewNs(ret, (xmlChar*)LASSO_WSUTIL1_HREF, (xmlChar*)LASSO_WSUTIL1_PREFIX);
xmlNewNsProp(ret, ns, (xmlChar*)"Id", (xmlChar*)LASSO_SOAP_BODY(node)->Id);
}
return ret;
}
GType
lasso_soap_body_get_type()
{

View File

@ -2405,3 +2405,62 @@ lasso_make_signature_context_from_path_or_string(char *filename_or_buffer, const
}
return context;
}
xmlNs *
get_or_define_ns(xmlNode *xmlnode, const xmlChar *ns_uri, const xmlChar *advised_prefix) {
xmlNs *ns;
char prefix[20];
int i = 1;
ns = xmlSearchNsByHref(NULL, xmlnode, ns_uri);
if (ns)
return ns;
/* Try with the advised prefix */
if (advised_prefix) {
ns = xmlSearchNs(NULL, xmlnode, BAD_CAST prefix);
if (! ns) { /* If not taken, use it */
return xmlNewNs(xmlnode, ns_uri, BAD_CAST advised_prefix);
}
}
/* Create a prefix from scratch */
do {
sprintf(prefix, "ns%u", i);
i++;
ns = xmlSearchNs(NULL, xmlnode, BAD_CAST prefix);
} while (ns);
return xmlNewNs(xmlnode, ns_uri, BAD_CAST prefix);
}
void
set_qname_attribute(xmlNode *node,
const xmlChar *attribute_ns_prefix,
const xmlChar *attribute_ns_href,
const xmlChar *attribute_name,
const xmlChar *prefix,
const xmlChar *href,
const xmlChar *name) {
xmlNs *type_ns;
xmlNs *xsi_ns;
xmlChar *value;
xsi_ns = get_or_define_ns(node, attribute_ns_href, attribute_ns_prefix);
type_ns = get_or_define_ns(node, href, prefix);
value = BAD_CAST g_strdup_printf("%s:%s", type_ns->prefix, name);
xmlSetNsProp(node, xsi_ns, attribute_name, value);
lasso_release_string(value);
}
void
set_xsi_type(xmlNode *node,
const xmlChar *type_ns_prefix,
const xmlChar *type_ns_href,
const xmlChar *type_name) {
set_qname_attribute(node,
BAD_CAST LASSO_XSI_PREFIX,
BAD_CAST LASSO_XSI_HREF,
BAD_CAST "type",
type_ns_prefix,
type_ns_href,
type_name);
}

File diff suppressed because it is too large Load Diff