diff options
| author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-02-17 10:15:24 +0000 |
|---|---|---|
| committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2010-02-17 10:15:24 +0000 |
| commit | 5d9e6f550a6813c4ff30e5f77cb49ea717ccc689 (patch) | |
| tree | 23afe53816d81e82af38d5d17e69b17f00d3463c | |
| parent | d3932515858eeefe645c877cb505a228fef76f12 (diff) | |
| download | lasso-5d9e6f550a6813c4ff30e5f77cb49ea717ccc689.tar.gz lasso-5d9e6f550a6813c4ff30e5f77cb49ea717ccc689.tar.xz lasso-5d9e6f550a6813c4ff30e5f77cb49ea717ccc689.zip | |
Core: add a lasso_xmlnode_to_string function
* lasso/xml/tools.c lasso/xml/private.h:
lots of functions duplicate this code, so we factorized it there.
It has two parameters, the xmlnode and boolean deciding whether to
format the resulting content (good for reading but bad for
signatures).
| -rw-r--r-- | lasso/xml/private.h | 1 | ||||
| -rw-r--r-- | lasso/xml/tools.c | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lasso/xml/private.h b/lasso/xml/private.h index a8711b70..4ca174d8 100644 --- a/lasso/xml/private.h +++ b/lasso/xml/private.h @@ -227,6 +227,7 @@ xmlSecKey* lasso_xmlsec_load_private_key(const char *filename_or_buffer, const c xmlDocPtr lasso_xml_parse_file(const char *filepath); xmlDocPtr lasso_xml_parse_memory_with_error(const char *buffer, int size, xmlError *error); xmlSecKeyPtr lasso_xmlsec_load_key_info(xmlNode *key_descriptor); +char* lasso_xmlnode_to_string(xmlNode *node, gboolean format); #ifdef __cplusplus } diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c index 2202f3c6..deb06801 100644 --- a/lasso/xml/tools.c +++ b/lasso/xml/tools.c @@ -2100,3 +2100,35 @@ next: cleanup: return result; } + +/** + * lasso_xmlnode_to_string: + * @xmlnode: an #xmlNode structure + * @format: whether to allow formatting (it break XML signatures) + * + * Transform an XML node to a C string + * + * Return value: a newly allocated C string + */ +char* +lasso_xmlnode_to_string(xmlNode *node, gboolean format) +{ + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; + xmlChar *buffer; + char *str; + + if (! node) + return NULL; + + handler = xmlFindCharEncodingHandler("utf-8"); + buf = xmlAllocOutputBuffer(handler); + xmlNodeDumpOutput(buf, NULL, node, 0, format ? 1 : 0, "utf-8"); + xmlOutputBufferFlush(buf); + buffer = buf->conv ? buf->conv->content : buf->buffer->content; + /* do not mix XML and GLib strings, so we must copy */ + str = g_strdup((char*)buffer); + xmlOutputBufferClose(buf); + + return str; +} |
