Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/XMLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <openssl/x509.h>
#include <xmlsec/openssl/evp.h>

#include <algorithm>
#include <array>
#include <fstream>

Expand Down Expand Up @@ -579,28 +580,30 @@ struct XMLDocument: public unique_free_d<xmlFreeDoc>, 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<xmlSchemaFreeParserCtxt>(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<xmlSchemaFree>(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<xmlSchemaFree>(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
{
auto validate = make_unique_ptr<xmlSchemaFreeValidCtxt>(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;
Expand Down
3 changes: 2 additions & 1 deletion src/crypto/TSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down