From 4eaed37011e5fe26d9326dc1b93ed87115997004 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Tue, 30 Jun 2026 14:02:51 +0300 Subject: [PATCH] Fix XSD loading warning IB-8215 Signed-off-by: Raul Metsma --- src/XMLDocument.h | 17 ++++++++++------- src/crypto/TSL.cpp | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/XMLDocument.h b/src/XMLDocument.h index 9d706b831..6c046149d 100644 --- a/src/XMLDocument.h +++ b/src/XMLDocument.h @@ -37,6 +37,7 @@ #include #include +#include #include #include @@ -579,20 +580,22 @@ struct XMLDocument: public unique_free_d, public XMLNode struct XMLSchema { - auto parser(const std::string &path) + auto parser(std::string &&path) { + std::replace(path.begin(), path.end(), '\\', '/'); auto parser = make_unique_ptr(xmlSchemaNewParserCtxt(path.c_str())); if(!parser) THROW("Failed to create schema parser context %s", path.c_str()); xmlSchemaSetParserErrors(parser.get(), schemaValidationError, schemaValidationWarning, nullptr); - return parser; + auto schema = make_unique_ptr(xmlSchemaParse(parser.get())); + if(!schema) + THROW("Failed to parse schema %s", path.c_str()); + return schema; } - XMLSchema(const std::string &path) - : d(make_unique_ptr(xmlSchemaParse(parser(path).get()))) + XMLSchema(std::string path) + : d(parser(std::move(path))) { - if(!d) - THROW("Failed to parse schema %s", path.c_str()); } void validate(const XMLDocument &doc) const @@ -600,7 +603,7 @@ struct XMLSchema auto validate = make_unique_ptr(xmlSchemaNewValidCtxt(d.get())); if(!validate) THROW("Failed to create schema validation context"); - Exception e(EXCEPTION_PARAMS("Failed to XML with schema")); + Exception e(EXCEPTION_PARAMS("Failed to validate XML with schema")); xmlSchemaSetValidErrors(validate.get(), schemaValidationError, schemaValidationWarning, &e); if(xmlSchemaValidateDoc(validate.get(), doc.get()) != 0) throw e; diff --git a/src/crypto/TSL.cpp b/src/crypto/TSL.cpp index 694e62e02..7a5901cb3 100644 --- a/src/crypto/TSL.cpp +++ b/src/crypto/TSL.cpp @@ -98,7 +98,8 @@ TSL::TSL(string file) if(get()) { try { - validateSchema(File::path(Conf::instance()->xsdPath(), "ts_119612v020201_201601xsd.xsd")); + static const XMLSchema schema(File::path(Conf::instance()->xsdPath(), "ts_119612v020201_201601xsd.xsd")); + validateSchema(schema); } catch(const Exception &e) { ERR("Failed to validate TSL schema: %s, %s", path.c_str(), e.msg().c_str()); reset();