--- a/src/OdfGenerator.cxx 2026-10-27 15:13:15.676222664 +0100 +++ b/src/OdfGenerator.cxx 2026-10-27 15:13:15.688504347 +0100 @@ -40,7 +40,6 @@ #include -#include #include "DocumentElement.hxx" #include "GraphicFunctions.hxx" @@ -99,75 +98,11 @@ struct XMLException {}; -const char *xmlCast(const xmlChar *const str) +// PubOpener: libxml2 is only needed to embed equation objects, which +// Publisher files never contain, so we leave it out. +void appendXML(const std::string &, DocumentElementVector &) { - return reinterpret_cast(str); -} - -static void addAttributes(xmlAttributePtr attr, std::shared_ptr &element) -{ - for (; attr; attr = xmlAttributePtr(attr->next)) - { - std::string value; - - for (xmlNodePtr node = attr->children; node; node = node->next) - if (node->type == XML_TEXT_NODE) - value += xmlCast(node->content); - element->addAttribute(xmlCast(attr->name), value.c_str()); - } -} - -static void appendNameSpace(xmlNsPtr nSpace, std::shared_ptr &element) -{ - if (nSpace->type==XML_NAMESPACE_DECL && nSpace->href) - { - std::string tag("xmlns"); - if (nSpace->prefix) tag+=std::string(":")+xmlCast(nSpace->prefix); - std::string value(xmlCast(nSpace->href)); - element->addAttribute(tag.c_str(), value.c_str()); - // FIXME: look also next to check if there is other namespace - } -} - -static void appendElements(xmlNodePtr node, DocumentElementVector &out, bool rootNode=false) -{ - for (; node; node = node->next) - { - switch (node->type) - { - case XML_ELEMENT_NODE: - { - auto element = xmlElementPtr(node); - auto tag = std::make_shared(xmlCast(element->name)); - out.push_back(tag); - if (rootNode && node->nsDef) appendNameSpace(node->nsDef, tag); - addAttributes(element->attributes, tag); - appendElements(element->children, out); - out.push_back(std::make_shared(xmlCast(element->name))); - break; - } - case XML_TEXT_NODE: - out.push_back(std::make_shared(xmlCast(node->content))); - break; - default: - break; - } - } -} - -void appendXML(const std::string &data, DocumentElementVector &out) -{ - std::unique_ptr doc - { - // FIXME: coverity warns that using XML_PARSE_RECOVER is unsafe, - // but libstaroffice generates α , so we must first fix libstaroffice before removing XML_PARSE_RECOVER - xmlReadDoc(reinterpret_cast(data.c_str()), "", nullptr, - XML_PARSE_RECOVER | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET | XML_PARSE_NOCDATA | XML_PARSE_NSCLEAN), - xmlFreeDoc}; - if (!doc) - throw XMLException(); - - appendElements(doc->children, out, true); + throw XMLException(); } }