diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-12-09 00:04:23 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-12-22 01:21:00 +0100 |
| commit | 63357f32e8229b9d734b0c0ab38cc062dcfec393 (patch) | |
| tree | 0f9f6eddc9e7e9532e07b86dc95452ec72ef187d | |
| parent | aeb2f36ede25d6e8ce583592c23bbb1dfb05041e (diff) | |
Also check PKL XML.
| -rw-r--r-- | src/verify.cc | 25 | ||||
| -rw-r--r-- | test/verify_test.cc | 20 | ||||
| -rw-r--r-- | xsd/SMPTE-429-8-2006-PKL.xsd | 60 |
3 files changed, 99 insertions, 6 deletions
diff --git a/src/verify.cc b/src/verify.cc index 2815166c..e20cafb3 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -142,7 +142,9 @@ public: maybe_add (XMLValidationError(e)); } - void resetErrors() {} + void resetErrors() { + _errors.clear (); + } list<XMLValidationError> errors () const { return _errors; @@ -158,7 +160,10 @@ private: "from the one specified in instance document 'http://www.w3.org/2001/03/xml.xsd'" || e.message() == "schema document '/home/carl/src/libdcp/xsd/xmldsig-core-schema.xsd' has different target namespace " - "from the one specified in instance document 'http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd'" + "from the one specified in instance document 'http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd'" || + e.message() == + "schema document '/home/carl/src/libdcp/xsd/SMPTE-429-8-2006-PKL.xsd' has different target namespace " + "from the one specified in instance document 'http://www.smpte-ra.org/schemas/429-8/2006/PKL'" ) { return; } @@ -246,6 +251,7 @@ validate_xml (boost::filesystem::path xml_file, boost::filesystem::path xsd_dtd_ schema["http://www.w3.org/2000/09/xmldsig#"] = "xmldsig-core-schema.xsd"; schema["http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"] = "xmldsig-core-schema.xsd"; schema["http://www.smpte-ra.org/schemas/429-7/2006/CPL"] = "SMPTE-429-7-2006-CPL.xsd"; + schema["http://www.smpte-ra.org/schemas/429-8/2006/PKL"] = "SMPTE-429-8-2006-PKL.xsd"; schema["http://www.w3.org/2001/03/xml.xsd"] = "xml.xsd"; string locations; @@ -273,7 +279,6 @@ validate_xml (boost::filesystem::path xml_file, boost::filesystem::path xsd_dtd_ } catch (...) { throw MiscError("Unknown exception from xerces"); } - } XMLPlatformUtils::Terminate (); @@ -349,7 +354,7 @@ dcp::verify ( BOOST_FOREACH (XMLValidationError i, errors) { notes.push_back (VerificationNote( VerificationNote::VERIFY_ERROR, VerificationNote::Code::XML_VALIDATION_ERROR, - String::compose("%1 (on line %2)", i.message(), i.line()) + String::compose("%1 (file %2, line %3)", i.message(), cpl->file()->string(), i.line()) )); } @@ -416,6 +421,18 @@ dcp::verify ( } } } + + BOOST_FOREACH (shared_ptr<PKL> pkl, dcp->pkls()) { + stage ("Checking PKL", pkl->file()); + + list<XMLValidationError> errors = validate_xml (pkl->file().get(), xsd_dtd_directory); + BOOST_FOREACH (XMLValidationError i, errors) { + notes.push_back (VerificationNote( + VerificationNote::VERIFY_ERROR, VerificationNote::Code::XML_VALIDATION_ERROR, + String::compose("%1 (file %2, line %3)", i.message(), pkl->file()->string(), i.line()) + )); + } + } } return notes; diff --git a/test/verify_test.cc b/test/verify_test.cc index 737c2fb9..f6f7ee43 100644 --- a/test/verify_test.cc +++ b/test/verify_test.cc @@ -108,7 +108,7 @@ void dump_notes (list<dcp::VerificationNote> const & notes) { BOOST_FOREACH (dcp::VerificationNote i, notes) { - std::cout << dcp::note_to_string(i) << "\n"; + std::cout << dcp::note_to_string(i) << " " << i.note().get_value_or("") << "\n"; } } @@ -119,6 +119,7 @@ BOOST_AUTO_TEST_CASE (verify_test1) list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress, "xsd"); boost::filesystem::path const cpl_file = "build/test/verify_test1/cpl_81fb54df-e1bf-4647-8788-ea7ba154375b.xml"; + boost::filesystem::path const pkl_file = "build/test/verify_test1/pkl_ae8a9818-872a-4f86-8493-11dfdea03e09.xml"; list<pair<string, optional<boost::filesystem::path> > >::const_iterator st = stages.begin(); BOOST_CHECK_EQUAL (st->first, "Checking DCP"); @@ -140,6 +141,10 @@ BOOST_AUTO_TEST_CASE (verify_test1) BOOST_REQUIRE (st->second); BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical("build/test/verify_test1/audio.mxf")); ++st; + BOOST_CHECK_EQUAL (st->first, "Checking PKL"); + BOOST_REQUIRE (st->second); + BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical(pkl_file)); + ++st; BOOST_REQUIRE (st == stages.end()); dump_notes (notes); @@ -186,7 +191,9 @@ BOOST_AUTO_TEST_CASE (verify_test3) list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress, "xsd"); - BOOST_REQUIRE_EQUAL (notes.size(), 3); + dump_notes (notes); + + BOOST_REQUIRE_EQUAL (notes.size(), 6); list<dcp::VerificationNote>::const_iterator i = notes.begin(); BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR); BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::CPL_HASH_INCORRECT); @@ -197,6 +204,15 @@ BOOST_AUTO_TEST_CASE (verify_test3) BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR); BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::PKL_CPL_SOUND_HASHES_DISAGREE); ++i; + BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR); + BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::XML_VALIDATION_ERROR); + ++i; + BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR); + BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::XML_VALIDATION_ERROR); + ++i; + BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR); + BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::XML_VALIDATION_ERROR); + ++i; } /* Corrupt the ContentKind in the CPL */ diff --git a/xsd/SMPTE-429-8-2006-PKL.xsd b/xsd/SMPTE-429-8-2006-PKL.xsd new file mode 100644 index 00000000..01d10afe --- /dev/null +++ b/xsd/SMPTE-429-8-2006-PKL.xsd @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema targetNamespace="http://www.smpte-ra.org/schemas/429-8/2007/PKL" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pkl="http://www.smpte-ra.org/schemas/429-8/2007/PKL" elementFormDefault="qualified" attributeFormDefault="unqualified"> + + <xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd"/> + <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/> + + <!-- PackingList --> + <xs:element name="PackingList" type="pkl:PackingListType"/> + <xs:complexType name="PackingListType"> + <xs:sequence> + <xs:element name="Id" type="pkl:UUID"/> + <xs:element name="AnnotationText" type="pkl:UserText" minOccurs="0"/> + <xs:element name="IconId" type="pkl:UUID" minOccurs="0"/> + <xs:element name="IssueDate" type="xs:dateTime"/> + <xs:element name="Issuer" type="pkl:UserText"/> + <xs:element name="Creator" type="pkl:UserText"/> + <xs:element name="GroupId" type="pkl:UUID" minOccurs="0"/> + <xs:element name="AssetList"> + <xs:complexType> + <xs:sequence> + <xs:element name="Asset" type="pkl:AssetType" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="Signer" type="ds:KeyInfoType" minOccurs="0"/> + <xs:element ref="ds:Signature" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + + <!-- Asset --> + <xs:element name="Asset" type="pkl:AssetType"/> + <xs:complexType name="AssetType"> + <xs:sequence> + <xs:element name="Id" type="pkl:UUID"/> + <xs:element name="AnnotationText" type="pkl:UserText" minOccurs="0"/> + <xs:element name="Hash" type="xs:base64Binary"/> + <xs:element name="Size" type="xs:positiveInteger"/> + <xs:element name="Type" type="xs:string"/> + <xs:element name="OriginalFileName" type="pkl:UserText" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + + <!-- UUID --> + <xs:simpleType name="UUID"> + <xs:restriction base="xs:anyURI"> + <xs:pattern value="urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/> + </xs:restriction> + </xs:simpleType> + + <!--UserText--> + <xs:complexType name="UserText"> + <xs:simpleContent> + <xs:extension base="xs:string"> + <xs:attribute name="language" type="xs:language" use="optional" default="en"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + +</xs:schema> + |
