summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2012-09-28 20:58:10 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2012-09-28 20:58:24 (GMT)
commitbd0f935a2450b5779a01e9e5053267ec4cac94d6 (patch)
treec717cd2c11a4f0c272a38eae778cc54039f4d4d2
parente94015f8bcc168c9882348d2e8c5a5138ea56676 (diff)
downloadlasso-bd0f.zip
lasso-bd0f.tar.gz
lasso-bd0f.tar.bz2
Rewrite all xmlNode serialization code to be compatible with libxml 2.9.0libxml2.9-compat
Libxml stopped exposing the internal of the xmlOutputBuffer structure; it was replace by proper use of the API and of the xmlBuffer structure. There could be regression for older version of libxml as some functions appeared in recent version of libxml; but the reference API document does not give any introduction date for functions so it's hard to be sure.
-rw-r--r--bindings/java/wrapper_top.c40
-rw-r--r--bindings/php5/wrapper_source_top.c42
-rw-r--r--bindings/python/wrapper_top.c34
-rw-r--r--docs/reference/lasso/lasso-sections.txt8
-rw-r--r--lasso/id-ff/lecp.c24
-rw-r--r--lasso/id-ff/session.c23
-rw-r--r--lasso/key.c6
-rw-r--r--lasso/saml-2.0/ecp.c25
-rw-r--r--lasso/xml/tools.c39
9 files changed, 112 insertions, 129 deletions
diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c
index dfdec34..54bdeef 100644
--- a/bindings/java/wrapper_top.c
+++ b/bindings/java/wrapper_top.c
@@ -282,35 +282,39 @@ jstring_to_string(JNIEnv *env, jstring jstr, char **str) {
/* xmlNode handling */
+static xmlBuffer*
+xmlnode_to_xmlbuffer(xmlNode *node)
+{
+ xmlOutputBufferPtr output_buffer;
+ xmlBuffer *buffer;
+
+ if (! node)
+ return NULL;
+
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL);
+ xmlNodeDumpOutput(output_buffer, NULL, node, 0, 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
+
+ return buffer;
+}
+
static int
xml_node_to_jstring(JNIEnv *env, xmlNode *xmlnode, jstring *jstr) {
- xmlOutputBufferPtr buf = NULL;
+ xmlBuffer *buffer;
g_error_if_fail(env);
if (! xmlnode) {
*jstr = NULL;
return 1;
}
-
- buf = xmlAllocOutputBuffer(NULL);
- if (buf) {
- int ret = 1;
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL);
- xmlOutputBufferFlush(buf);
- xmlChar *str = NULL;
- if (buf->conv == NULL) {
- str = buf->buffer->content;
- } else {
- str = buf->conv->content;
- }
- ret = string_to_jstring(env, (char*)str, jstr);
- xmlOutputBufferClose(buf);
- return ret;
- } else {
+ buffer = xmlnode_to_xmlbuffer(xmlnode);
+ if (! buffer) {
exception(env, "could not alloc an xml output buffer");
return 0;
}
- return 1;
+ return string_to_jstring(env, (char*)xmlBufferContent(buffer), jstr);
}
/** Convert a java string to an xml node. Return 0 if it failed with an exception
diff --git a/bindings/php5/wrapper_source_top.c b/bindings/php5/wrapper_source_top.c
index 67a279a..0b1db97 100644
--- a/bindings/php5/wrapper_source_top.c
+++ b/bindings/php5/wrapper_source_top.c
@@ -119,31 +119,41 @@ free_glist(GList **list, GFunc free_function) {
}
/* Conversion functions */
+static xmlBuffer*
+xmlnode_to_xmlbuffer(xmlNode *node)
+{
+ xmlOutputBufferPtr output_buffer;
+ xmlBuffer *buffer;
+
+ if (! node)
+ return NULL;
+
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL);
+ xmlNodeDumpOutput(output_buffer, NULL, node, 0, 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
+
+ return buffer;
+}
+
static char*
get_string_from_xml_node(xmlNode *xmlnode)
{
- xmlOutputBufferPtr buf;
- char *xmlString;
+ xmlBuffer *buffer;
+ char *result;
if (xmlnode == NULL) {
return NULL;
}
-
- buf = xmlAllocOutputBuffer(NULL);
- if (buf == NULL) {
- xmlString = NULL;
+ buffer = xmlnode_to_xmlbuffer(xmlnode);
+ if (buffer == NULL) {
+ result = NULL;
} else {
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL);
- xmlOutputBufferFlush(buf);
- if (buf->conv == NULL) {
- xmlString = estrdup((char*)buf->buffer->content);
- } else {
- xmlString = estrdup((char*)buf->conv->content);
- }
- xmlOutputBufferClose(buf);
+ result = estrdup((char*)xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
}
-
- return xmlString;
+ return result;
}
static xmlNode*
diff --git a/bindings/python/wrapper_top.c b/bindings/python/wrapper_top.c
index c80bf1d..a9312b7 100644
--- a/bindings/python/wrapper_top.c
+++ b/bindings/python/wrapper_top.c
@@ -103,28 +103,40 @@ get_dict_from_hashtable_of_strings(GHashTable *value)
return proxy;
}
+static xmlBuffer*
+xmlnode_to_xmlbuffer(xmlNode *node)
+{
+ xmlOutputBufferPtr output_buffer;
+ xmlBuffer *buffer;
+
+ if (! node)
+ return NULL;
+
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL);
+ xmlNodeDumpOutput(output_buffer, NULL, node, 0, 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
+
+ return buffer;
+}
+
static PyObject*
get_pystring_from_xml_node(xmlNode *xmlnode)
{
- xmlOutputBufferPtr buf;
PyObject *pystring = NULL;
+ xmlBuffer *buffer;
if (xmlnode == NULL) {
return NULL;
}
+ buffer = xmlnode_to_xmlbuffer(xmlnode);
- buf = xmlAllocOutputBuffer(NULL);
- if (buf == NULL) {
+ if (buffer == NULL) {
pystring = NULL;
} else {
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL);
- xmlOutputBufferFlush(buf);
- if (buf->conv == NULL) {
- pystring = PyString_FromString((char*)buf->buffer->content);
- } else {
- pystring = PyString_FromString((char*)buf->conv->content);
- }
- xmlOutputBufferClose(buf);
+ pystring = PyString_FromString((char*)xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
}
return pystring;
diff --git a/docs/reference/lasso/lasso-sections.txt b/docs/reference/lasso/lasso-sections.txt
index cdd019f..505a718 100644
--- a/docs/reference/lasso/lasso-sections.txt
+++ b/docs/reference/lasso/lasso-sections.txt
@@ -1,4 +1,10 @@
<SECTION>
+<FILE>utilities</FILE>
+<TITLE>Utilities</TITLE>
+LassoServe_CLASS
+</SECTION>
+
+<SECTION>
<FILE>server</FILE>
<TITLE>LassoServer</TITLE>
LassoServer
@@ -6059,7 +6065,7 @@ LASSO_PROVIDER_ERROR_MISSING_PUBLIC_KEY
</SECTION>
<SECTION>
-<FILE>init</FILE>
+<FILE>lasso</FILE>
<TITLE>Initialization functions</TITLE>
LASSO_EXPORT
LASSO_EXPORT_VAR
diff --git a/lasso/id-ff/lecp.c b/lasso/id-ff/lecp.c
index f175691..cdff031 100644
--- a/lasso/id-ff/lecp.c
+++ b/lasso/id-ff/lecp.c
@@ -58,8 +58,6 @@ lasso_lecp_build_authn_request_envelope_msg(LassoLecp *lecp)
LassoProfile *profile;
gchar *assertionConsumerServiceURL;
xmlNode *msg;
- xmlOutputBuffer *buf;
- xmlCharEncodingHandler *handler;
g_return_val_if_fail(LASSO_IS_LECP(lecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
@@ -89,16 +87,7 @@ lasso_lecp_build_authn_request_envelope_msg(LassoLecp *lecp)
LASSO_PROFILE(lecp)->server->certificate;
msg = lasso_node_get_xmlNode(LASSO_NODE(lecp->authnRequestEnvelope), FALSE);
- /* msg is not SOAP but straight XML */
- handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, msg, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
-
- lasso_assign_string(profile->msg_body,
- (char*)(buf->conv ? buf->conv->content : buf->buffer->content));
- xmlOutputBufferClose(buf);
- xmlFreeNode(msg);
+ lasso_assign_new_string(profile->msg_body, lasso_xmlnode_to_string(msg, 0, 0))
if (profile->msg_body == NULL) {
return LASSO_PROFILE_ERROR_BUILDING_REQUEST_FAILED;
@@ -299,8 +288,6 @@ lasso_lecp_process_authn_request_envelope_msg(LassoLecp *lecp, const char *reque
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
xmlNode *soap_envelope, *soap_body, *authn_request;
- xmlOutputBuffer *buf;
- xmlCharEncodingHandler *handler;
g_return_val_if_fail(LASSO_IS_LECP(lecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
g_return_val_if_fail(request_msg != NULL, LASSO_PARAM_ERROR_INVALID_VALUE);
@@ -337,13 +324,8 @@ lasso_lecp_process_authn_request_envelope_msg(LassoLecp *lecp, const char *reque
soap_body = xmlNewTextChild(soap_envelope, NULL, (xmlChar*)"Body", NULL);
xmlAddChild(soap_body, authn_request);
- handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, soap_envelope, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
- LASSO_PROFILE(lecp)->msg_body = g_strdup( (char*)(
- buf->conv ? buf->conv->content : buf->buffer->content));
- xmlOutputBufferClose(buf);
+ lasso_assign_new_string(LASSO_PROFILE(lecp)->msg_body,
+ lasso_xmlnode_to_string(soap_envelope, 0, 0));
xmlFreeNode(soap_envelope);
diff --git a/lasso/id-ff/session.c b/lasso/id-ff/session.c
index d5294ff..67b0147 100644
--- a/lasso/id-ff/session.c
+++ b/lasso/id-ff/session.c
@@ -723,27 +723,12 @@ add_assertion_childnode(gchar *key, LassoLibAssertion *value, DumpContext *conte
xmlChar *
xmlNode_to_base64(xmlNode *node) {
- xmlOutputBufferPtr buf = NULL;
- xmlCharEncodingHandlerPtr handler = NULL;
- xmlChar *buffer = NULL;
+ gchar *buffer = NULL;
xmlChar *ret = NULL;
- handler = xmlFindCharEncodingHandler("utf-8");
- if (! handler)
- goto cleanup;
- buf = xmlAllocOutputBuffer(handler);
- if (! buf)
- goto cleanup;
- xmlNodeDumpOutput(buf, NULL, node, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
- buffer = buf->conv ? buf->conv->content : buf->buffer->content;
-
- ret = xmlSecBase64Encode(buffer, strlen((char*)buffer), 0);
-
-cleanup:
- if (buf)
- xmlOutputBufferClose(buf);
-
+ buffer = lasso_xmlnode_to_string(node, 0, 0);
+ ret = xmlSecBase64Encode(BAD_CAST buffer, strlen((char*)buffer), 0);
+ lasso_release_string(buffer);
return ret;
}
diff --git a/lasso/key.c b/lasso/key.c
index 2f6dcec..747492c 100644
--- a/lasso/key.c
+++ b/lasso/key.c
@@ -134,7 +134,7 @@ lasso_key_new_for_signature_from_context(LassoSignatureContext context) {
}
/**
- * lasso_key_new_for_signature_from_file;
+ * lasso_key_new_for_signature_from_file:
* @filename_or_buffer: a file path of a string containing the key PEM or Base64 encoded
* @password: an eventual password to decoded the private key contained in @buffer
* @signature_method: the signature method to associate to this key
@@ -159,7 +159,7 @@ lasso_key_new_for_signature_from_file(char *filename_or_buffer,
}
/**
- * lasso_key_new_for_signature_from_memory;
+ * lasso_key_new_for_signature_from_memory:
* @buffer: a byte buffer of size @size
* @size: the size of @buffer
* @password: an eventual password to decoded the private key contained in @buffer
@@ -188,7 +188,7 @@ lasso_key_new_for_signature_from_memory(const void *buffer,
}
/**
- * lasso_key_new_for_signature_from_base64_string;
+ * lasso_key_new_for_signature_from_base64_string:
* @base64_string: a NULL-terminated string containing a base64 encode representation of the key
* @password: an eventual password to decoded the private key contained in @buffer
* @signature_method: the signature method to associate to this key
diff --git a/lasso/saml-2.0/ecp.c b/lasso/saml-2.0/ecp.c
index 06dfff2..52c909b 100644
--- a/lasso/saml-2.0/ecp.c
+++ b/lasso/saml-2.0/ecp.c
@@ -132,8 +132,6 @@ lasso_ecp_process_authn_request_msg(LassoEcp *ecp, const char *authn_request_msg
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
xmlNode *xmlnode;
- xmlOutputBuffer *buf;
- xmlCharEncodingHandler *handler;
LassoProfile *profile;
LassoProvider *remote_provider;
@@ -174,13 +172,8 @@ lasso_ecp_process_authn_request_msg(LassoEcp *ecp, const char *authn_request_msg
xpathObj = NULL;
xmlnode = xmlDocGetRootElement(doc);
- handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
- LASSO_PROFILE(ecp)->msg_body = g_strdup(
- (char*)(buf->conv ? buf->conv->content : buf->buffer->content));
- xmlOutputBufferClose(buf);
+ lasso_assign_new_string(LASSO_PROFILE(ecp)->msg_body,
+ lasso_xmlnode_to_string(xmlnode, 0, 0))
lasso_release_doc(doc);
profile->remote_providerID = lasso_server_get_first_providerID_by_role(profile->server, LASSO_PROVIDER_ROLE_IDP);
@@ -210,8 +203,6 @@ lasso_ecp_process_response_msg(LassoEcp *ecp, const char *response_msg)
xmlXPathObject *xpathObj;
xmlNode *new_envelope, *header, *paos_response, *ecp_relay_state;
xmlNode *body = NULL;
- xmlOutputBuffer *buf;
- xmlCharEncodingHandler *handler;
xmlNs *soap_env_ns, *ecp_ns;
g_return_val_if_fail(LASSO_IS_ECP(ecp), LASSO_PARAM_ERROR_BAD_TYPE_OR_NULL_OBJ);
@@ -274,17 +265,9 @@ lasso_ecp_process_response_msg(LassoEcp *ecp, const char *response_msg)
}
xmlAddChild(new_envelope, body);
-
- handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, new_envelope, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
- LASSO_PROFILE(ecp)->msg_body = g_strdup(
- (char*)(buf->conv ? buf->conv->content : buf->buffer->content));
- xmlOutputBufferClose(buf);
-
+ lasso_assign_new_string(LASSO_PROFILE(ecp)->msg_body,
+ lasso_xmlnode_to_string(new_envelope, 0, 0))
lasso_release_doc(doc);
-
return 0;
}
diff --git a/lasso/xml/tools.c b/lasso/xml/tools.c
index 83db2d2..08c3eb1 100644
--- a/lasso/xml/tools.c
+++ b/lasso/xml/tools.c
@@ -36,6 +36,7 @@
#include <libxml/uri.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
+#include <libxml/xmlIO.h>
#include <openssl/pem.h>
#include <openssl/sha.h>
@@ -1023,9 +1024,9 @@ lasso_node_build_deflated_query(LassoNode *node)
gchar*
lasso_xmlnode_build_deflated_query(xmlNode *xmlnode)
{
- xmlOutputBufferPtr buf;
+ xmlOutputBuffer *output_buffer;
+ xmlBuffer *buffer;
xmlCharEncodingHandlerPtr handler = NULL;
- xmlChar *buffer;
xmlChar *ret, *b64_ret;
char *rret;
unsigned long in_len;
@@ -1033,18 +1034,19 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode)
z_stream stream;
handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 0, "utf-8");
- xmlOutputBufferFlush(buf);
- buffer = buf->conv ? buf->conv->content : buf->buffer->content;
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, handler);
+ xmlNodeDumpOutput(output_buffer, NULL, xmlnode, 0, 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
- in_len = strlen((char*)buffer);
+ in_len = strlen((char*)xmlBufferContent(buffer));
ret = g_malloc(in_len * 2);
/* deflating should never increase the required size but we are
* more conservative than that. Twice the size should be
* enough. */
- stream.next_in = buffer;
+ stream.next_in = (xmlChar*)xmlBufferContent(buffer);
stream.avail_in = in_len;
stream.next_out = ret;
stream.avail_out = in_len * 2;
@@ -1067,6 +1069,7 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode)
rc = deflateEnd(&stream);
}
}
+ xmlBufferFree(buffer);
if (rc != Z_OK) {
lasso_release(ret);
message(G_LOG_LEVEL_CRITICAL, "Failed to deflate");
@@ -1074,7 +1077,6 @@ lasso_xmlnode_build_deflated_query(xmlNode *xmlnode)
}
b64_ret = xmlSecBase64Encode(ret, stream.total_out, 0);
- xmlOutputBufferClose(buf);
lasso_release(ret);
ret = xmlURIEscapeStr(b64_ret, NULL);
@@ -2246,22 +2248,21 @@ cleanup:
char*
lasso_xmlnode_to_string(xmlNode *node, gboolean format, int level)
{
- xmlOutputBufferPtr buf;
- xmlCharEncodingHandlerPtr handler = NULL;
- xmlChar *buffer;
+ xmlOutputBufferPtr output_buffer;
+ xmlBuffer *buffer;
char *str;
if (! node)
return NULL;
- handler = xmlFindCharEncodingHandler("utf-8");
- buf = xmlAllocOutputBuffer(handler);
- xmlNodeDumpOutput(buf, NULL, node, level, format ? 1 : 0, "utf-8");
- xmlOutputBufferFlush(buf);
- buffer = buf->conv ? buf->conv->content : buf->buffer->content;
+ buffer = xmlBufferCreate();
+ output_buffer = xmlOutputBufferCreateBuffer(buffer, NULL);
+ xmlNodeDumpOutput(output_buffer, NULL, node, level, format ? 1 : 0, NULL);
+ xmlOutputBufferClose(output_buffer);
+ xmlBufferAdd(buffer, BAD_CAST "", 1);
/* do not mix XML and GLib strings, so we must copy */
- str = g_strdup((char*)buffer);
- xmlOutputBufferClose(buf);
+ str = g_strdup((char*)xmlBufferContent(buffer));
+ xmlBufferFree(buffer);
return str;
}