Merge remote-tracking branch 'origin/libxml2.9-compat'

This commit is contained in:
Benjamin Dauvergne 2013-07-30 15:31:26 +02:00
commit f48cd5bbcf
9 changed files with 112 additions and 129 deletions

View File

@ -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

View File

@ -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*

View File

@ -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;

View File

@ -1,3 +1,9 @@
<SECTION>
<FILE>utilities</FILE>
<TITLE>Utilities</TITLE>
LassoServe_CLASS
</SECTION>
<SECTION>
<FILE>server</FILE>
<TITLE>LassoServer</TITLE>
@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}