diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-16 11:12:58 +0100 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-16 11:39:24 +0100 |
| commit | 154812b401e3845977b3a4892dbc5e5a0b9d03cf (patch) | |
| tree | bdd43fb563f124bbce837345ed7c25c11086831d /lasso/id-ff/profile.c | |
| parent | 9a31985671edfaf877a1254e308bf7d61f1219fa (diff) | |
| download | lasso-154812b401e3845977b3a4892dbc5e5a0b9d03cf.tar.gz lasso-154812b401e3845977b3a4892dbc5e5a0b9d03cf.tar.xz lasso-154812b401e3845977b3a4892dbc5e5a0b9d03cf.zip | |
[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.
Diffstat (limited to 'lasso/id-ff/profile.c')
| -rw-r--r-- | lasso/id-ff/profile.c | 76 |
1 files changed, 6 insertions, 70 deletions
diff --git a/lasso/id-ff/profile.c b/lasso/id-ff/profile.c index c1c86daa..749fb119 100644 --- a/lasso/id-ff/profile.c +++ b/lasso/id-ff/profile.c @@ -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 |
