summaryrefslogtreecommitdiff
path: root/src/pkl_internal.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-04-24 22:38:52 +0200
committerCarl Hetherington <cth@carlh.net>2022-04-24 22:38:52 +0200
commit85c565b56de05e93617a8dfd633d6f9d6e9cb30a (patch)
treeecde1c29df68d91c749fd33ea7e4175a3a3716d6 /src/pkl_internal.cc
parentec520e1a5ed27b3eb414627acf7ad7f9cd661346 (diff)
Try to remove the PKL object, and make it so that we don't keepdcp-editor2
the PKL assets around after reading them. But verification needs to see those assets, to check the hashes.
Diffstat (limited to 'src/pkl_internal.cc')
-rw-r--r--src/pkl_internal.cc136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/pkl_internal.cc b/src/pkl_internal.cc
new file mode 100644
index 00000000..eee6f8dc
--- /dev/null
+++ b/src/pkl_internal.cc
@@ -0,0 +1,136 @@
+/*
+ Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+/** @file src/pkl.cc
+ * @brief PKL class
+ */
+
+
+#include "dcp_assert.h"
+#include "exceptions.h"
+#include "pkl_internal.h"
+#include "raw_convert.h"
+#include "util.h"
+#include "warnings.h"
+LIBDCP_DISABLE_WARNINGS
+#include <libxml++/libxml++.h>
+LIBDCP_ENABLE_WARNINGS
+#include <iostream>
+
+
+using std::string;
+using std::shared_ptr;
+using std::make_shared;
+using std::vector;
+using boost::optional;
+using namespace dcp;
+
+
+static string const pkl_interop_ns = "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#";
+static string const pkl_smpte_ns = "http://www.smpte-ra.org/schemas/429-8/2007/PKL";
+
+
+PKLMetadata
+read_pkl (boost::filesystem::path file, vector<PKLAsset>& assets)
+{
+ cxml::Document pkl ("PackingList");
+ pkl.read_file (file);
+
+ PKLMetadata metadata;
+
+ if (pkl.namespace_uri() == pkl_interop_ns) {
+ metadata.standard = Standard::INTEROP;
+ } else if (pkl.namespace_uri() == pkl_smpte_ns) {
+ metadata.standard = Standard::SMPTE;
+ } else {
+ boost::throw_exception(XMLError("Unrecognised packing list namesapce " + pkl.namespace_uri()));
+ }
+
+ metadata.id = remove_urn_uuid(pkl.string_child("Id"));
+ metadata.annotation_text = pkl.optional_string_child("AnnotationText");
+ metadata.issue_date = pkl.string_child("IssueDate");
+ metadata.issuer = pkl.string_child("Issuer");
+ metadata.creator = pkl.string_child("Creator");
+
+ for (auto i: pkl.node_child("AssetList")->node_children("Asset")) {
+ assets.push_back(PKLAsset(i));
+ }
+
+ return metadata;
+}
+
+
+void
+write_pkl (boost::filesystem::path file, PKLMetadata const& metadata, vector<PKLAsset> const& assets, shared_ptr<const CertificateChain> signer)
+{
+ DCP_ASSERT(metadata.standard);
+
+ xmlpp::Document doc;
+ xmlpp::Element* pkl;
+ if (metadata.standard == Standard::INTEROP) {
+ pkl = doc.create_root_node("PackingList", pkl_interop_ns);
+ } else {
+ pkl = doc.create_root_node("PackingList", pkl_smpte_ns);
+ }
+
+ pkl->add_child("Id")->add_child_text("urn:uuid:" + metadata.id);
+ if (metadata.annotation_text) {
+ pkl->add_child("AnnotationText")->add_child_text(*metadata.annotation_text);
+ }
+ pkl->add_child("IssueDate")->add_child_text(metadata.issue_date);
+ pkl->add_child("Issuer")->add_child_text(metadata.issuer);
+ pkl->add_child("Creator")->add_child_text(metadata.creator);
+
+ auto asset_list = pkl->add_child("AssetList");
+ for (auto const& i: assets) {
+ auto asset = asset_list->add_child("Asset");
+ asset->add_child("Id")->add_child_text ("urn:uuid:" + i.id());
+ if (i.annotation_text()) {
+ asset->add_child("AnnotationText")->add_child_text (*i.annotation_text());
+ }
+ asset->add_child("Hash")->add_child_text(i.hash());
+ asset->add_child("Size")->add_child_text(raw_convert<string>(i.size()));
+ asset->add_child("Type")->add_child_text(i.type());
+ }
+
+ indent (pkl, 0);
+
+ if (signer) {
+ signer->sign (pkl, *metadata.standard);
+ }
+
+ doc.write_to_file_formatted (file.string(), "UTF-8");
+}
+
+