summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lasso/xml/private.h1
-rw-r--r--lasso/xml/tools.c32
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;
+}