Use PKL types rather than file extensions.
[libdcp.git] / src / pkl.h
1 /*
2     Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     libdcp is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
18
19     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #ifndef LIBDCP_PKL_H
35 #define LIBDCP_PKL_H
36
37 #include "object.h"
38 #include "types.h"
39 #include "util.h"
40 #include "certificate_chain.h"
41 #include <libcxml/cxml.h>
42 #include <boost/filesystem.hpp>
43
44 namespace dcp {
45
46 class PKL : public Object
47 {
48 public:
49         PKL (Standard standard, boost::optional<std::string> annotation_text, std::string issue_date, std::string issuer, std::string creator)
50                 : _standard (standard)
51                 , _annotation_text (annotation_text)
52                 , _issue_date (issue_date)
53                 , _issuer (issuer)
54                 , _creator (creator)
55         {}
56
57         explicit PKL (boost::filesystem::path file);
58
59         Standard standard () const {
60                 return _standard;
61         }
62
63         std::string hash (std::string id) const;
64         std::string type (std::string id) const;
65
66         void add_asset (std::string id, boost::optional<std::string> annotation_text, std::string hash, int64_t size, std::string type);
67         void write (boost::filesystem::path file, boost::shared_ptr<const CertificateChain> signer) const;
68
69 private:
70
71         class Asset : public Object
72         {
73         public:
74                 Asset (cxml::ConstNodePtr node)
75                         : Object (remove_urn_uuid(node->string_child("Id")))
76                         , annotation_text (node->optional_string_child("AnnotationText"))
77                         , hash (node->string_child("Hash"))
78                         , size (node->number_child<int64_t>("Size"))
79                         , type (node->string_child("Type"))
80                 {}
81
82                 Asset (std::string id_, boost::optional<std::string> annotation_text_, std::string hash_, int64_t size_, std::string type_)
83                         : Object (id_)
84                         , annotation_text (annotation_text_)
85                         , hash (hash_)
86                         , size (size_)
87                         , type (type_)
88                 {}
89
90                 boost::optional<std::string> annotation_text;
91                 std::string hash;
92                 int64_t size;
93                 std::string type;
94         };
95
96         Standard _standard;
97         boost::optional<std::string> _annotation_text;
98         std::string _issue_date;
99         std::string _issuer;
100         std::string _creator;
101         std::list<boost::shared_ptr<Asset> > _asset_list;
102 };
103
104 }
105
106 #endif