diff options
| author | Frederic Peters <fpeters@entrouvert.com> | 2007-04-19 20:29:59 +0000 |
|---|---|---|
| committer | Frederic Peters <fpeters@entrouvert.com> | 2007-04-19 20:29:59 +0000 |
| commit | fce9becb19dcf6501c760c952416654fb3920fad (patch) | |
| tree | d6fe1c4c2a1ded7d6105faa400059f97305a170a | |
| parent | 5bdab807c421c8e084952af64c005f8384b27e27 (diff) | |
a little bit of imagination to avoid new classes for each and every
simple element with a different name.
| -rw-r--r-- | lasso/xml/Makefile.am | 2 | ||||
| -rw-r--r-- | lasso/xml/misc_text_node.c | 183 | ||||
| -rw-r--r-- | lasso/xml/misc_text_node.h | 81 | ||||
| -rw-r--r-- | lasso/xml/ws/wsa_metadata.c | 3 | ||||
| -rw-r--r-- | lasso/xml/xml.c | 22 |
5 files changed, 288 insertions, 3 deletions
diff --git a/lasso/xml/Makefile.am b/lasso/xml/Makefile.am index 5e167f7d..4e647ca2 100644 --- a/lasso/xml/Makefile.am +++ b/lasso/xml/Makefile.am @@ -169,6 +169,7 @@ liblasso_xml_la_SOURCES = \ lib_scoping.c \ lib_status_response.c \ lib_subject.c \ + misc_text_node.c \ saml_advice.c \ saml_assertion.c \ saml_attribute.c \ @@ -222,6 +223,7 @@ liblassoinclude_HEADERS = \ lib_scoping.h \ lib_status_response.h \ lib_subject.h \ + misc_text_node.h \ saml_advice.h \ saml_assertion.h \ saml_attribute.h \ diff --git a/lasso/xml/misc_text_node.c b/lasso/xml/misc_text_node.c new file mode 100644 index 00000000..80afc3a4 --- /dev/null +++ b/lasso/xml/misc_text_node.c @@ -0,0 +1,183 @@ +/* $Id: misc_text_node.c,v 1.0 2005/10/14 15:17:55 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004-2007 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: See AUTHORS file in top-level directory. + * + * 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 "misc_text_node.h" + +/*****************************************************************************/ +/* private methods */ +/*****************************************************************************/ + + +static struct XmlSnippet schema_snippets[] = { + { "content", SNIPPET_TEXT_CHILD, + G_STRUCT_OFFSET(LassoMiscTextNode, content) }, + {NULL, 0, 0} +}; + +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; + + 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); + + return xmlnode; +} + +static int +init_from_xml(LassoNode *node, xmlNode *xmlnode) +{ + LassoMiscTextNode *n = LASSO_MISC_TEXT_NODE(node); + int rc; + + rc = parent_class->init_from_xml(node, xmlnode); + if (rc) return rc; + + n->ns_href = g_strdup((char*)xmlnode->ns->href); + n->ns_prefix = g_strdup((char*)xmlnode->ns->prefix); + n->name = g_strdup((char*)xmlnode->name); + + return 0; +} + +static void +finalize(GObject *object) +{ + LassoMiscTextNode *t = LASSO_MISC_TEXT_NODE(object); + + g_free(t->name); + g_free(t->ns_href); + g_free(t->ns_prefix); + + G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(t)); +} + + +/*****************************************************************************/ +/* instance and class init functions */ +/*****************************************************************************/ + +static void +instance_init(LassoMiscTextNode *node) +{ + node->content = NULL; + + node->name = NULL; + node->ns_href = NULL; + node->ns_prefix = NULL; +} + +static void +class_init(LassoMiscTextNodeClass *klass) +{ + LassoNodeClass *nclass = LASSO_NODE_CLASS(klass); + + parent_class = g_type_class_peek_parent(klass); + nclass->get_xmlNode = get_xmlNode; + nclass->init_from_xml = init_from_xml; + nclass->node_data = g_new0(LassoNodeClassData, 1); + + G_OBJECT_CLASS(nclass)->finalize = finalize; + + lasso_node_class_set_nodename(nclass, "XXX"); + lasso_node_class_add_snippets(nclass, schema_snippets); +} + +GType +lasso_misc_text_node_get_type() +{ + static GType this_type = 0; + + if (!this_type) { + static const GTypeInfo this_info = { + sizeof (LassoMiscTextNodeClass), + NULL, + NULL, + (GClassInitFunc) class_init, + NULL, + NULL, + sizeof(LassoMiscTextNode), + 0, + (GInstanceInitFunc) instance_init, + }; + + this_type = g_type_register_static(LASSO_TYPE_NODE, + "LassoMiscTextNode", &this_info, 0); + } + return this_type; +} + +/** + * lasso_misc_text_node_new: + * + * Creates a new #LassoMiscTextNode object. + * + * Return value: a newly created #LassoMiscTextNode object + **/ +LassoNode* +lasso_misc_text_node_new() +{ + return g_object_new(LASSO_TYPE_MISC_TEXT_NODE, NULL); +} + + +/** + * lasso_misc_text_node_new_with_string: + * @content: + * + * Creates a new #LassoMiscTextNode object and initializes it + * with @content. + * + * Return value: a newly created #LassoMiscTextNode object + **/ +LassoNode* +lasso_misc_text_node_new_with_string(char *content) +{ + LassoMiscTextNode *object; + object = g_object_new(LASSO_TYPE_MISC_TEXT_NODE, NULL); + object->content = g_strdup(content); + return LASSO_NODE(object); +} + diff --git a/lasso/xml/misc_text_node.h b/lasso/xml/misc_text_node.h new file mode 100644 index 00000000..20f4a9f6 --- /dev/null +++ b/lasso/xml/misc_text_node.h @@ -0,0 +1,81 @@ +/* $Id: misc_text_node.h,v 1.0 2005/10/14 15:17:55 fpeters Exp $ + * + * Lasso - A free implementation of the Liberty Alliance specifications. + * + * Copyright (C) 2004-2007 Entr'ouvert + * http://lasso.entrouvert.org + * + * Authors: See AUTHORS file in top-level directory. + * + * 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_MISC_TEXT_NODE_H__ +#define __LASSO_MISC_TEXT_NODE_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include <lasso/xml/xml.h> + +#define LASSO_TYPE_MISC_TEXT_NODE (lasso_misc_text_node_get_type()) +#define LASSO_MISC_TEXT_NODE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), LASSO_TYPE_MISC_TEXT_NODE, \ + LassoMiscTextNode)) +#define LASSO_MISC_TEXT_NODE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), LASSO_TYPE_MISC_TEXT_NODE, \ + LassoMiscTextNodeClass)) +#define LASSO_IS_MISC_TEXT_NODE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), LASSO_TYPE_MISC_TEXT_NODE)) +#define LASSO_IS_MISC_TEXT_NODE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), LASSO_TYPE_MISC_TEXT_NODE)) +#define LASSO_MISC_TEXT_NODE_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), LASSO_TYPE_MISC_TEXT_NODE, \ + LassoMiscTextNodeClass)) + +typedef struct _LassoMiscTextNode LassoMiscTextNode; +typedef struct _LassoMiscTextNodeClass LassoMiscTextNodeClass; + + +struct _LassoMiscTextNode { + LassoNode parent; + + /*< public >*/ + /* elements */ + char *content; + + /*< private >*/ + char *name; + char *ns_href; + char *ns_prefix; +}; + + +struct _LassoMiscTextNodeClass { + LassoNodeClass parent; +}; + +LASSO_EXPORT GType lasso_misc_text_node_get_type(void); +LASSO_EXPORT LassoNode* lasso_misc_text_node_new(void); + +LASSO_EXPORT LassoNode* lasso_misc_text_node_new_with_string(char *content); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __LASSO_MISC_TEXT_NODE_H__ */ diff --git a/lasso/xml/ws/wsa_metadata.c b/lasso/xml/ws/wsa_metadata.c index 563949f9..093c160b 100644 --- a/lasso/xml/ws/wsa_metadata.c +++ b/lasso/xml/ws/wsa_metadata.c @@ -41,7 +41,8 @@ static struct XmlSnippet schema_snippets[] = { - { "", SNIPPET_LIST_NODES, G_STRUCT_OFFSET(LassoWsAddrMetadata, any) }, + { "", SNIPPET_LIST_NODES | SNIPPET_ANY, + G_STRUCT_OFFSET(LassoWsAddrMetadata, any) }, { "any", SNIPPET_ATTRIBUTE | SNIPPET_ANY, G_STRUCT_OFFSET(LassoWsAddrMetadata, attributes) }, {NULL, 0, 0} diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index 6de7f03a..0caa83f4 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -877,9 +877,27 @@ lasso_node_impl_init_from_xml(LassoNode *node, xmlNode *xmlnode) tmp = lasso_saml_name_identifier_new_from_xmlNode(t); } else if (type == SNIPPET_LIST_NODES) { GList **location = value; - LassoNode *n = lasso_node_new_from_xmlNode_with_type(t, + LassoNode *n; + n = lasso_node_new_from_xmlNode_with_type(t, snippet->class_name); - *location = g_list_append(*location, n); + if (n == NULL && snippet_any == snippet && + t->properties == NULL && t->children && + t->children->type == XML_TEXT_NODE && + t->children->next == NULL) { + /* unknown, but no attributes, and content + * is text ? -> use generic object */ + n = lasso_node_new_from_xmlNode_with_type(t, + "LassoMiscTextNode"); + } + + if (n) { + *location = g_list_append(*location, n); + } else { + /* failed to do sth with */ + message(G_LOG_LEVEL_WARNING, + "Failed to do sth with %s", + t->name); + } } else if (type == SNIPPET_LIST_CONTENT) { GList **location = value; xmlChar *s = xmlNodeGetContent(t); |
