42 #include "filesystem.h"
48 LIBDCP_DISABLE_WARNINGS
49 #include <libxml++/libxml++.h>
50 LIBDCP_ENABLE_WARNINGS
55 using std::shared_ptr;
56 using std::make_shared;
58 using boost::optional;
62 static string const pkl_interop_ns =
"http://www.digicine.com/PROTO-ASDCP-PKL-20040311#";
63 static string const pkl_smpte_ns =
"http://www.smpte-ra.org/schemas/429-8/2007/PKL";
65 static string const pkl_resolve_smpte_ns =
"http://www.smpte-ra.org/schemas/2067-2/2016/PKL";
68 PKL::PKL(boost::filesystem::path file, vector<dcp::VerificationNote>* notes)
71 cxml::Document pkl (
"PackingList");
72 pkl.read_file(dcp::filesystem::fix_long_path(file));
74 if (pkl.namespace_uri() == pkl_interop_ns) {
75 _standard = Standard::INTEROP;
76 }
else if (pkl.namespace_uri() == pkl_smpte_ns) {
77 _standard = Standard::SMPTE;
78 }
else if (pkl.namespace_uri() == pkl_resolve_smpte_ns) {
79 _standard = Standard::SMPTE;
83 dcp::VerificationNote::Type::ERROR,
91 boost::throw_exception(
XMLError(
"Unrecognised packing list namespace " + pkl.namespace_uri()));
94 _id = remove_urn_uuid (pkl.string_child (
"Id"));
95 _annotation_text = pkl.optional_string_child (
"AnnotationText");
96 _issue_date = pkl.string_child (
"IssueDate");
97 _issuer = pkl.string_child (
"Issuer");
98 _creator = pkl.string_child (
"Creator");
100 for (
auto i: pkl.node_child(
"AssetList")->node_children(
"Asset")) {
101 _assets.push_back(make_shared<Asset>(i));
107 PKL::add_asset(std::string
id, boost::optional<std::string> annotation_text, std::string hash, int64_t size, std::string type, std::string original_filename)
109 _assets.push_back(make_shared<Asset>(
id, annotation_text, hash, size, type, original_filename));
114 PKL::write_xml (boost::filesystem::path file, shared_ptr<const CertificateChain> signer)
const
118 if (_standard == Standard::INTEROP) {
119 pkl = doc.create_root_node(
"PackingList", pkl_interop_ns);
121 pkl = doc.create_root_node(
"PackingList", pkl_smpte_ns);
124 cxml::add_text_child(pkl,
"Id",
"urn:uuid:" + _id);
125 if (_annotation_text) {
126 cxml::add_text_child(pkl,
"AnnotationText", *_annotation_text);
128 cxml::add_text_child(pkl,
"IssueDate", _issue_date);
129 cxml::add_text_child(pkl,
"Issuer", _issuer);
130 cxml::add_text_child(pkl,
"Creator", _creator);
132 auto asset_list = cxml::add_child(pkl,
"AssetList");
133 for (
auto i: _assets) {
134 auto asset = cxml::add_child(asset_list,
"Asset");
135 cxml::add_text_child(asset,
"Id",
"urn:uuid:" + i->id());
136 if (i->annotation_text()) {
137 cxml::add_text_child(asset,
"AnnotationText", *i->annotation_text());
139 cxml::add_text_child(asset,
"Hash", i->hash());
140 cxml::add_text_child(asset,
"Size", raw_convert<string>(i->size()));
141 cxml::add_text_child(asset,
"Type", i->type());
142 if (
auto filename = i->original_filename()) {
143 cxml::add_text_child(asset,
"OriginalFileName", *filename);
150 signer->sign (pkl, _standard);
153 doc.write_to_file_formatted(dcp::filesystem::fix_long_path(
file).
string(),
"UTF-8");
159 PKL::hash (
string id)
const
161 for (
auto i: _assets) {
172 PKL::type (
string id)
const
174 for (
auto i: _assets) {
boost::optional< boost::filesystem::path > file() const
boost::optional< boost::filesystem::path > _file
Exceptions thrown by libdcp.
Namespace for everything in libdcp.
Methods for conversion to/from string.
Utility methods and classes.
dcp::verify() method and associated code