diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2012-09-28 22:58:10 +0200 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2012-09-28 22:58:24 +0200 |
commit | bd0f935a2450b5779a01e9e5053267ec4cac94d6 (patch) | |
tree | c717cd2c11a4f0c272a38eae778cc54039f4d4d2 /bindings | |
parent | e94015f8bcc168c9882348d2e8c5a5138ea56676 (diff) | |
download | lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.tar.gz lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.tar.xz lasso-bd0f935a2450b5779a01e9e5053267ec4cac94d6.zip |
Rewrite all xmlNode serialization code to be compatible with libxml 2.9.0
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.
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/java/wrapper_top.c | 40 | ||||
-rw-r--r-- | bindings/php5/wrapper_source_top.c | 42 | ||||
-rw-r--r-- | bindings/python/wrapper_top.c | 34 |
3 files changed, 71 insertions, 45 deletions
diff --git a/bindings/java/wrapper_top.c b/bindings/java/wrapper_top.c index dfdec346..54bdeef6 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 67a279a4..0b1db97d 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 c80bf1d6..a9312b7c 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; |