libdcp
verify.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018-2021 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 
40 #ifndef LIBDCP_VERIFY_H
41 #define LIBDCP_VERIFY_H
42 
43 
44 #include "decrypted_kdm.h"
45 #include <boost/any.hpp>
46 #include <boost/filesystem.hpp>
47 #include <boost/function.hpp>
48 #include <boost/optional.hpp>
49 #include <map>
50 #include <string>
51 #include <vector>
52 
53 
54 /* windows.h defines this but we want to use it */
55 #undef ERROR
56 
57 
58 namespace dcp {
59 
60 
61 class DCP;
62 class TextAsset;
63 
64 
66 {
67 public:
68  enum class Type {
69  OK,
70  ERROR,
71  BV21_ERROR,
72  WARNING
73  };
74 
97  // If you change the next line, also look in doc/manual/verifier.py in DCP-o-matic
98  // as it looks for it when compiling the manual. Also, in this enum:
99  // [...] will be taken as a reference to a section of Bv2.1
100  // _foo_ means foo should be written as a piece of code
101  enum class Code {
105  FAILED_READ,
154  INVALID_XML,
305  MISSING_HASH,
311  MISSING_FFOC,
313  MISSING_LFOC,
424  EMPTY_TEXT,
478  MISSING_FONT,
524  };
525 
526  VerificationNote (Type type, Code code)
527  : _type (type)
528  , _code (code)
529  {}
530 
531  VerificationNote (Type type, Code code, std::string note)
532  : _type (type)
533  , _code (code)
534  {
535  _data[Data::NOTE] = note;
536  }
537 
538  VerificationNote (Type type, Code code, boost::filesystem::path file)
539  : _type (type)
540  , _code (code)
541  {
542  _data[Data::FILE] = file;
543  }
544 
545  VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file)
546  : _type (type)
547  , _code (code)
548  {
549  _data[Data::NOTE] = note;
550  _data[Data::FILE] = file;
551  }
552 
553  VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line)
554  : _type (type)
555  , _code (code)
556  {
557  _data[Data::NOTE] = note;
558  _data[Data::FILE] = file;
559  _data[Data::LINE] = line;
560  }
561 
562  Type type () const {
563  return _type;
564  }
565 
566  Code code () const {
567  return _code;
568  }
569 
570 private:
571  enum class Data {
572  NOTE,
573  FILE,
574  LINE,
575  FRAME,
576  COMPONENT,
577  SIZE,
578  ID,
579  OTHER_ID,
580  FRAME_RATE,
581  CPL_ID,
582  CALCULATED_HASH,
583  REFERENCE_HASH
584  };
585 
586  template <class T>
587  boost::optional<T> data(Data key) const
588  {
589  auto iter = _data.find(key);
590  if (iter == _data.end()) {
591  return {};
592  }
593  return boost::any_cast<T>(iter->second);
594  }
595 
596 public:
597  boost::optional<std::string> note () const {
598  return data<std::string>(Data::NOTE);
599  }
600 
601  boost::optional<boost::filesystem::path> file () const {
602  return data<boost::filesystem::path>(Data::FILE);
603  }
604 
605  boost::optional<uint64_t> line () const {
606  return data<uint64_t>(Data::LINE);
607  }
608 
609  VerificationNote& set_frame(int frame) {
610  _data[Data::FRAME] = frame;
611  return *this;
612  }
613 
614  boost::optional<int> frame() const {
615  return data<int>(Data::FRAME);
616  }
617 
618  VerificationNote& set_component(int component) {
619  _data[Data::COMPONENT] = component;
620  return *this;
621  }
622 
623  boost::optional<int> component() const {
624  return data<int>(Data::COMPONENT);
625  }
626 
627  VerificationNote& set_size(int size) {
628  _data[Data::SIZE] = size;
629  return *this;
630  }
631 
632  boost::optional<int> size() const {
633  return data<int>(Data::SIZE);
634  }
635 
636  VerificationNote& set_id(std::string id) {
637  _data[Data::ID] = id;
638  return *this;
639  }
640 
641  boost::optional<std::string> id() const {
642  return data<std::string>(Data::ID);
643  }
644 
645  VerificationNote& set_other_id(std::string other_id) {
646  _data[Data::OTHER_ID] = other_id;
647  return *this;
648  }
649 
650  boost::optional<std::string> other_id() const {
651  return data<std::string>(Data::OTHER_ID);
652  }
653 
654  VerificationNote& set_frame_rate(int frame_rate) {
655  _data[Data::FRAME_RATE] = frame_rate;
656  return *this;
657  }
658 
659  boost::optional<int> frame_rate() const {
660  return data<int>(Data::FRAME_RATE);
661  }
662 
663  VerificationNote& set_calculated_hash(std::string hash) {
664  _data[Data::CALCULATED_HASH] = hash;
665  return *this;
666  }
667 
668  boost::optional<std::string> calculated_hash() const {
669  return data<std::string>(Data::CALCULATED_HASH);
670  }
671 
672  VerificationNote& set_reference_hash(std::string hash) {
673  _data[Data::REFERENCE_HASH] = hash;
674  return *this;
675  }
676 
677  boost::optional<std::string> reference_hash() const {
678  return data<std::string>(Data::REFERENCE_HASH);
679  }
680 
681  VerificationNote& set_cpl_id(std::string id) {
682  _data[Data::CPL_ID] = id;
683  return *this;
684  }
685 
686  boost::optional<std::string> cpl_id() const {
687  return data<std::string>(Data::CPL_ID);
688  }
689 
690 private:
691  Type _type;
692  Code _code;
693  std::map<Data, boost::any> _data;
694 };
695 
696 
698 {
700  boost::optional<boost::uintmax_t> maximum_asset_size_for_hash_check;
703  bool check_asset_hashes = true;
704 };
705 
706 
708 {
709  std::vector<VerificationNote> notes;
710  std::vector<std::shared_ptr<dcp::DCP>> dcps;
711 };
712 
713 
714 VerificationResult verify(
715  std::vector<boost::filesystem::path> directories,
716  std::vector<dcp::DecryptedKDM> kdms,
717  std::function<void (std::string, boost::optional<boost::filesystem::path>)> stage,
718  std::function<void (float)> progress,
719  VerificationOptions options = {},
720  boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>()
721  );
722 
723 std::string note_to_string(
725  std::function<std::string (std::string)> process_string = [](std::string s) { return s; },
726  std::function<std::string (std::string)> process_filename = [](std::string s) { return s; }
727  );
728 
729 bool operator== (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
730 bool operator!=(dcp::VerificationNote const& a, dcp::VerificationNote const& b);
731 bool operator< (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
732 
733 std::ostream& operator<<(std::ostream& s, dcp::VerificationNote const& note);
734 
735 }
736 
737 #endif
Definition: data.h:52
@ NOTE
further information about the error
@ LINE
error line number within the FILE
@ FILE
path of file containing the error
@ BV21_ERROR
may not always be considered an error, but violates a "shall" requirement of Bv2.1
DecryptedKDM class.
Namespace for everything in libdcp.
Definition: array_data.h:50
boost::optional< boost::uintmax_t > maximum_asset_size_for_hash_check
< If set, any assets larger than this number of bytes will not have their hashes checked
Definition: verify.h:700