From 2884799ea8c635ea5849fed3bea77b099a541de0 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 24 Mar 2011 12:26:59 +0100 Subject: fs34b: added some diagnostics, so next time a bug like #i117507# happens we will not - at least in a non-product build - silently ignore it Conflicts: forms/source/xforms/submission/serialization_app_xml.cxx --- .../xforms/submission/serialization_app_xml.cxx | 54 +++++++++++++--------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'forms') diff --git a/forms/source/xforms/submission/serialization_app_xml.cxx b/forms/source/xforms/submission/serialization_app_xml.cxx index 7c783bf8adaa..dc0a990695fb 100644 --- a/forms/source/xforms/submission/serialization_app_xml.cxx +++ b/forms/source/xforms/submission/serialization_app_xml.cxx @@ -30,7 +30,6 @@ #include "serialization.hxx" #include "serialization_app_xml.hxx" -#include #include #include #include @@ -39,8 +38,13 @@ #include #include +#include +#include + #include +#include + CSerializationAppXML::CSerializationAppXML() : m_aFactory(comphelper::getProcessServiceFactory()) , m_aPipe(CSS::io::Pipe::create(comphelper::getProcessComponentContext())) @@ -63,33 +67,39 @@ CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::X CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW); aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW); } - if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE) - return; + ENSURE_OR_RETURN_VOID( aNode->getNodeType() == CSS::xml::dom::NodeType_ELEMENT_NODE, + "CSerializationAppXML::serialize_node: invalid node type!" ); // clone the node to a new document and serialize that document - CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY); - if (aTunnel.is()) + CSS::uno::Reference< CSS::lang::XUnoTunnel > xTunnel( aNode, CSS::uno::UNO_QUERY ); + ENSURE_OR_RETURN_VOID( xTunnel.is(), "CSerializationAppXML::serialize_node: unknown implementation, cannot serialize!" ); + + xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( xTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) ); + ENSURE_OR_RETURN_VOID( aNodePtr != NULL, "CSerializationAppXML::serialize_node: unable to obtain the xmlNodePtr!" ); + + xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0"); + ENSURE_OR_RETURN_VOID( aDocPtr != NULL, "CSerializationAppXML::serialize_node: unable to create a temporary doc!" ); + + xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1); + if (aDocNodePtr != NULL) { - xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) ); - xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0"); - xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1); - if (aDocNodePtr != NULL) { - xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr); - xmlChar *buffer = NULL; - sal_Int32 size = 0; - xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size); - - // write the xml into the pipe through it's XOutputStream interface - m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size)); - xmlFree(buffer); + xmlAddChild( (xmlNodePtr)aDocPtr, aDocNodePtr ); + + xmlChar *buffer = NULL; + int size = 0; + xmlDocDumpMemory( aDocPtr, &buffer, &size ); + + if ( size > ::std::numeric_limits< sal_Int32 >::max() ) + { + OSL_ENSURE( false, "CSerializationAppXML::serialize_node: document too large, doesn't fit into a UNO sequence!" ); + size = ::std::numeric_limits< sal_Int32 >::max(); } - } else { - // can't get tunnel to native backend - // logic for generic implementation could be implemented here... - OSL_FAIL("unkown dom implementation, cannot serialize"); - return; + // write the xml into the pipe through it's XOutputStream interface + m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size)); + xmlFree(buffer); } + xmlFreeDoc( aDocPtr ); } void -- cgit