diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-04-06 13:11:30 +0000 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-04-06 13:11:30 +0000 |
commit | d26bdfaef7943fd2efc07290940525d521b8cf18 (patch) | |
tree | 2e8ac19ab469dfe9044ba83e6599af99dc8e0e14 | |
parent | 46044e2d9cf5d6859544638c6b99592e074ba855 (diff) | |
download | lasso-d26bdfaef7943fd2efc07290940525d521b8cf18.tar.gz lasso-d26bdfaef7943fd2efc07290940525d521b8cf18.tar.xz lasso-d26bdfaef7943fd2efc07290940525d521b8cf18.zip |
XML: add custom namespace definition handling
-rw-r--r-- | lasso/id-wsf-2.0/data_service.c | 10 | ||||
-rw-r--r-- | lasso/xml/private.h | 2 | ||||
-rw-r--r-- | lasso/xml/xml.c | 41 |
3 files changed, 53 insertions, 0 deletions
diff --git a/lasso/id-wsf-2.0/data_service.c b/lasso/id-wsf-2.0/data_service.c index a305aca5..d63f4d3f 100644 --- a/lasso/id-wsf-2.0/data_service.c +++ b/lasso/id-wsf-2.0/data_service.c @@ -51,6 +51,7 @@ #include "../xml/soap-1.1/soap_envelope.h" #include "../xml/soap-1.1/soap_fault.h" +#include "../xml/private.h" #include "../utils.h" #include "./private.h" #include "./idwsf2_helper.h" @@ -438,6 +439,12 @@ lasso_idwsf2_data_service_add_namespace(LassoIdWsf2DataService *service, const c return 0; } +static void +add_custom_namespace(const char *prefix, const char *href, LassoNode *node) +{ + lasso_node_add_custom_namespace(node, prefix, href); +} + /** * lasso_idwsf2_data_service_build_request_msg: * @service: a #LassoIdWsf2DataService object @@ -478,6 +485,9 @@ lasso_idwsf2_data_service_build_request_msg(LassoIdWsf2DataService *service, lasso_idwsf2_data_service_set_dst_service_type(query, service_type, prefix); } lasso_assign_list_of_gobjects(query->QueryItem, service->private_data->query_items); + g_hash_table_foreach(service->private_data->namespaces, + (GHFunc)add_custom_namespace, + query); break; case LASSO_IDWSF2_DATA_SERVICE_REQUEST_TYPE_MODIFY: if (service_type) { diff --git a/lasso/xml/private.h b/lasso/xml/private.h index 2b6423e4..60b6e2db 100644 --- a/lasso/xml/private.h +++ b/lasso/xml/private.h @@ -232,6 +232,8 @@ char* lasso_xmlnode_to_string(xmlNode *node, gboolean format, int level); gboolean lasso_string_to_xsd_integer(const char *str, long int *integer); void lasso_set_string_from_prop(char **str, xmlNode *node, xmlChar *name, xmlChar *ns); +void lasso_node_add_custom_namespace(LassoNode *node, const char *prefix, const char *href); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index c53dfec8..ea4c0ea9 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -759,12 +759,14 @@ struct _CustomElement { char *prefix; char *href; char *nodename; + GHashTable *namespaces; }; static struct _CustomElement * _lasso_node_new_custom_element() { struct _CustomElement *ret = g_new0(struct _CustomElement, 1); + ret->namespaces = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); return ret; } @@ -774,6 +776,7 @@ _lasso_node_free_custom_element(struct _CustomElement *custom_element) lasso_release_string(custom_element->prefix); lasso_release_string(custom_element->href); lasso_release_string(custom_element->nodename); + g_hash_table_destroy(custom_element->namespaces); lasso_release(custom_element); } @@ -852,6 +855,25 @@ lasso_node_set_custom_nodename(LassoNode *node, const char *nodename) lasso_assign_string(custom_element->nodename, nodename); } +/** + * lasso_node_add_custom_namespace: + * @prefix: prefix name + * @href: href url + * + * Add a custom namespace declaration at this node level + */ +void +lasso_node_add_custom_namespace(LassoNode *node, const char *prefix, + const char *href) +{ + struct _CustomElement *custom_element; + + custom_element = _lasso_node_get_custom_element_or_create(node); + g_return_if_fail(custom_element != NULL); + + g_hash_table_insert(custom_element->namespaces, g_strdup(prefix), g_strdup(href)); +} + /*****************************************************************************/ /* implementation methods */ /*****************************************************************************/ @@ -1280,6 +1302,23 @@ lasso_node_remove_signature(LassoNode *node) { /* private methods */ /*****************************************************************************/ +static void +_xmlnode_add_custom_namespace(const char *prefix, const char *href, xmlNode *xmlnode) +{ + xmlNs *existing = NULL; + + existing = xmlSearchNs(NULL, xmlnode, BAD_CAST prefix); + if (existing) { + if (g_strcmp0((char*)existing->href, href) != 0) { + message(G_LOG_LEVEL_CRITICAL, "Cannot add namespace %s='%s' to node %s, " + "namespace already exists with another href", prefix, href, + (char*)xmlnode->name); + } + return; + } + xmlNewNs(xmlnode, BAD_CAST href, BAD_CAST prefix); +} + static char* lasso_node_impl_build_query(LassoNode *node) { @@ -1355,6 +1394,8 @@ lasso_node_impl_get_xmlNode(LassoNode *node, gboolean lasso_dump) if (custom_element->nodename) { xmlNodeSetName(xmlnode, BAD_CAST (custom_element->nodename)); } + g_hash_table_foreach(custom_element->namespaces, + (GHFunc)_xmlnode_add_custom_namespace, xmlnode); } |