Cleanup: use std::function instead of boost::function.
[libdcp.git] / src / verify.h
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
35 /** @file  src/verify.h
36  *  @brief dcp::verify() method and associated code
37  */
38
39
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
63
64 class VerificationNote
65 {
66 public:
67         enum class Type {
68                 OK,
69                 ERROR,
70                 BV21_ERROR, ///< may not always be considered an error, but violates a "shall" requirement of Bv2.1
71                 WARNING
72         };
73
74         /** Codes for successful checks, errors or warnings from verifying DCPs.
75          *
76          *  The names should (in general) answer the question "what is wrong?" with an answer that begins "There is a ..."
77          *  e.g. "There is a INCORRECT_CPL_HASH"
78          *       "There is a MISSING_ASSET"
79          *
80          *  In general the pattern should be <negative-adjective> <noun>.
81          *  Some <negative-adjective>s are:
82          *
83          *  - INCORRECT: something, which could have any value, is wrong.
84          *  - INVALID: something, which should only be one of a set of values, is not in the set, or some preformatted
85          *             quantity (e.g. XML) is in the wrong format.
86          *  - MISMATCHED: two things, which should be the same, are not.
87          *  - EMPTY: something, which should have a value, has no value.
88          *  - MISSING: something, which should be present, is not.
89          *  - UNEXPECTED: something, which is present, should not be.
90          *  - FAILED: some part of the verification failed in some serious way.
91          *
92          *  Comments should clarify meaning and also say which of the optional fields (e.g. file)
93          *  are filled in when this code is used.
94          */
95
96         // If you change the next line, also look in doc/manual/verifier.py in DCP-o-matic
97         // as it looks for it when compiling the manual.  Also, in this enum:
98         //   [...]  will be taken as a reference to a section of Bv2.1
99         //   _foo_  means foo should be written as a piece of code
100         enum class Code {
101                 /** A general error when reading the DCP
102                  *  note contains (probably technical) details
103                  */
104                 FAILED_READ,
105                 /** The hash of the CPL in the PKL does not agree with the CPL file
106                  *  note contains CPL ID
107                  *  file contains CPL filename
108                  *  calculated_hash contains current hash of the CPL
109                  *  reference_hash contains the hash written in the PKL
110                  */
111                 MISMATCHED_CPL_HASHES,
112                 /** The frame rate given in a reel for the main picture is not 24, 25, 30, 48, 50 or 60
113                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
114                  */
115                 INVALID_PICTURE_FRAME_RATE,
116                 /** The hash of a main picture asset does not agree with the PKL file
117                  *  file contains the picture asset filename
118                  *  calculated_hash contains the current hash of the picture MXF
119                  *  reference_hash contains the hash from the PKL
120                  */
121                 INCORRECT_PICTURE_HASH,
122                 /** The hash of a main picture is different in the CPL and PKL
123                  *  file contains the picture asset filename
124                  */
125                 MISMATCHED_PICTURE_HASHES,
126                 /** The hash of a main sound asset does not agree with the PKL file
127                  *  file contains the sound asset filename
128                  *  calculated_hash contains the current hash of the picture MXF
129                  *  reference_hash contains the hash from the PKL
130                  */
131                 INCORRECT_SOUND_HASH,
132                 /** The hash of a main sound is different in the CPL and PKL
133                  *  file contains the sound asset filename
134                  */
135                 MISMATCHED_SOUND_HASHES,
136                 /** An assetmap's _<Path>_ entry is empty */
137                 EMPTY_ASSET_PATH,
138                 /** A file mentioned in an asset map cannot be found
139                  *  file contains the filename that is missing
140                  */
141                 MISSING_ASSET,
142                 /** The DCP contains both SMPTE and Interop-standard components */
143                 MISMATCHED_STANDARD,
144                 /** Some XML fails to validate against its XSD/DTD
145                  *  note contains the (probably technical) details
146                  *  file contains the invalid filename
147                  *  line contains the line number
148                  */
149                 INVALID_XML,
150                 /** No _ASSETMAP_ or _ASSETMAP.xml_ was found */
151                 MISSING_ASSETMAP,
152                 /** An asset's _IntrinsicDuration_ is less than 1 second
153                  *  note contains asset ID
154                  */
155                 INVALID_INTRINSIC_DURATION,
156                 /** An asset's _Duration_ is less than 1 second
157                  *  note contains asset ID
158                  */
159                 INVALID_DURATION,
160                 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 250Mbit/s
161                  *  file contains the picture asset filename
162                  */
163                 INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
164                 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 230Mbit/s
165                  *  file contains the picture asset filename
166                  */
167                 NEARLY_INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
168                 /** An asset that the CPL requires is not in this DCP; the DCP may be a VF
169                  *  note contains the asset ID
170                  */
171                 EXTERNAL_ASSET,
172                 /** A stereoscopic asset has an MXF which is marked as being monoscopic
173                  *  file contains the asset filename
174                  */
175                 THREED_ASSET_MARKED_AS_TWOD,
176                 /** DCP is Interop, not SMPTE [Bv2.1_6.1] */
177                 INVALID_STANDARD,
178                 /** A language or territory does not conform to RFC 5646 [Bv2.1_6.2.1]
179                  *  note contains the invalid language
180                  */
181                 INVALID_LANGUAGE,
182                 /** A picture asset does not have one of the required Bv2.1 sizes (in pixels) [Bv2.1_7.1]
183                  *  note contains the incorrect size as "<width>x<height>"
184                  *  file contains the asset filename
185                  */
186                 INVALID_PICTURE_SIZE_IN_PIXELS,
187                 /** A picture asset is 2K but is not at 24, 25 or 48 fps as required by Bv2.1 [Bv2.1_7.1]
188                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
189                  *  file contains the asset filename
190                  */
191                 INVALID_PICTURE_FRAME_RATE_FOR_2K,
192                 /** A picture asset is 4K but is not at 24fps as required by Bv2.1 [Bv2.1_7.1]
193                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
194                  *  file contains the asset filename
195                  */
196                 INVALID_PICTURE_FRAME_RATE_FOR_4K,
197                 /** A picture asset is 4K but is 3D which is not allowed by Bv2.1 [Bv2.1_7.1]
198                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
199                  *  file contains the asset filename
200                  */
201                 INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D,
202                 /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1]
203                  *  note contains the invalid size in bytes
204                  *  file contains the asset filename
205                  */
206                 INVALID_CLOSED_CAPTION_XML_SIZE_IN_BYTES,
207                 /** Any timed text asset's total files is larger than 115MB [Bv2.1_7.2.1]
208                  *  note contains the invalid size in bytes
209                  *  file contains the asset filename
210                  */
211                 INVALID_TIMED_TEXT_SIZE_IN_BYTES,
212                 /** The total size of all a timed text asset's fonts is larger than 10MB [Bv2.1_7.2.1]
213                  *  note contains the invalid size in bytes
214                  *  file contains the asset filename
215                  */
216                 INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES,
217                 /** Some SMPTE subtitle XML has no _<Language>_ tag [Bv2.1_7.2.2]
218                  *  file contains the asset filename
219                  */
220                 MISSING_SUBTITLE_LANGUAGE,
221                 /** Not all subtitle assets specify the same _<Language>_ tag [Bv2.1_7.2.2] */
222                 MISMATCHED_SUBTITLE_LANGUAGES,
223                 /** Some SMPTE subtitle XML has no _<StartTime>_ tag [Bv2.1_7.2.3]
224                  *  file contains the asset filename
225                  */
226                 MISSING_SUBTITLE_START_TIME,
227                 /** Some SMPTE subtitle XML has a non-zero _<StartTime>_ tag [Bv2.1_7.2.3]
228                  *  file contains the asset filename
229                  */
230                 INVALID_SUBTITLE_START_TIME,
231                 /** The first subtitle or closed caption happens before 4s into the first reel [Bv2.1_7.2.4] */
232                 INVALID_SUBTITLE_FIRST_TEXT_TIME,
233                 /** At least one subtitle is less than the minimum of 15 frames suggested by [Bv2.1_7.2.5] */
234                 INVALID_SUBTITLE_DURATION,
235                 /** At least one pair of subtitles are separated by less than the the minimum of 2 frames suggested by [Bv2.1_7.2.5] */
236                 INVALID_SUBTITLE_SPACING,
237                 /** A subtitle lasts for longer than the reel which contains it */
238                 SUBTITLE_OVERLAPS_REEL_BOUNDARY,
239                 /** There are more than 3 subtitle lines in at least one place [Bv2.1_7.2.7] */
240                 INVALID_SUBTITLE_LINE_COUNT,
241                 /** There are more than 52 characters in at least one subtitle line [Bv2.1_7.2.7] */
242                 NEARLY_INVALID_SUBTITLE_LINE_LENGTH,
243                 /** There are more than 79 characters in at least one subtitle line [Bv2.1_7.2.7] */
244                 INVALID_SUBTITLE_LINE_LENGTH,
245                 /** There are more than 3 closed caption lines in at least one place [Bv2.1_7.2.6] */
246                 INVALID_CLOSED_CAPTION_LINE_COUNT,
247                 /** There are more than 32 characters in at least one closed caption line [Bv2.1_7.2.6] */
248                 INVALID_CLOSED_CAPTION_LINE_LENGTH,
249                 /** The audio sampling rate must be 48kHz [Bv2.1_7.3]
250                  *  note contains the invalid frame rate
251                  *  file contains the asset filename
252                  */
253                 INVALID_SOUND_FRAME_RATE,
254                 /** The CPL has no _<AnnotationText>_ tag [Bv2.1_8.1]
255                  *  note contains the CPL ID
256                  *  file contains the CPL filename
257                  */
258                 MISSING_CPL_ANNOTATION_TEXT,
259                 /** The _<AnnotationText>_ is not the same as the _<ContentTitleText>_ [Bv2.1_8.1]
260                  *  note contains the CPL ID
261                  *  file contains the CPL filename
262                  */
263                 MISMATCHED_CPL_ANNOTATION_TEXT,
264                 /** At least one asset in a reel does not have the same duration as the others */
265                 MISMATCHED_ASSET_DURATION,
266                 /** If one reel has a _MainSubtitle_, all must have them */
267                 MISSING_MAIN_SUBTITLE_FROM_SOME_REELS,
268                 /** If one reel has at least one _ClosedCaption_, all reels must have the same number of _ClosedCaptions_ */
269                 MISMATCHED_CLOSED_CAPTION_ASSET_COUNTS,
270                 /** MainSubtitle in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
271                  *  note contains the asset ID
272                  */
273                 MISSING_SUBTITLE_ENTRY_POINT,
274                 /** MainSubtitle _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
275                  *  note contains the asset ID
276                  */
277                 INCORRECT_SUBTITLE_ENTRY_POINT,
278                 /** Closed caption in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
279                  *  note contains the asset ID
280                  */
281                 MISSING_CLOSED_CAPTION_ENTRY_POINT,
282                 /** Closed caption _MainSubtitle_ _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
283                  *  note contains the asset ID
284                  */
285                 INCORRECT_CLOSED_CAPTION_ENTRY_POINT,
286                 /** _<Hash>_ must be present for assets in CPLs
287                  * note contains the asset ID
288                  */
289                 MISSING_HASH,
290                 /** If _ContentKind_ is Feature there must be a FFEC marker */
291                 MISSING_FFEC_IN_FEATURE,
292                 /** If _ContentKind_ is Feature there must be a FFMC marker */
293                 MISSING_FFMC_IN_FEATURE,
294                 /** There should be a FFOC marker */
295                 MISSING_FFOC,
296                 /** There should be a LFOC marker */
297                 MISSING_LFOC,
298                 /** The FFOC marker should be 1
299                  *  note contains the incorrect value.
300                  */
301                 INCORRECT_FFOC,
302                 /** The LFOC marker should be the last frame in the reel
303                  *  note contains the incorrect value
304                  */
305                 INCORRECT_LFOC,
306                 /** There must be a _<CompositionMetadataAsset>_
307                  *  note contains the CPL ID
308                  *  file contains the CPL filename
309                  */
310                 MISSING_CPL_METADATA,
311                 /** CPL metadata should contain _<VersionNumber>_ of 1, at least
312                  *  note contains the CPL ID
313                  *  file contains the CPL filename
314                  */
315                 MISSING_CPL_METADATA_VERSION_NUMBER,
316                 /** There must be an _<ExtensionMetadata>_ in _<CompositionMetadataAsset>_ [Bv2.1_8.6.3]
317                  *  note contains the CPL ID
318                  *  file contains the CPL filename
319                  */
320                 MISSING_EXTENSION_METADATA,
321                 /** _<ExtensionMetadata>_ does not have the correct form [Bv2.1_8.6.3]
322                  *  note contains details of what's wrong
323                  *  file contains the CPL filename
324                  */
325                 INVALID_EXTENSION_METADATA,
326                 /** A CPL containing encrypted content is not signed [Bv2.1_8.7]
327                  *  note contains the CPL ID
328                  *  file contains the CPL filename
329                  */
330                 UNSIGNED_CPL_WITH_ENCRYPTED_CONTENT,
331                 /** A PKL containing encrypted content is not signed [Bv2.1_8.7]
332                  *  note contains the PKL ID
333                  *  file contains the PKL filename
334                  */
335                 UNSIGNED_PKL_WITH_ENCRYPTED_CONTENT,
336                 /** If a PKL has one CPL its _<ContentTitleText>_ must be the same as the PKL's _<AnnotationText>_
337                  *  note contains the PKL ID
338                  *  file contains the PKL filename
339                  */
340                 MISMATCHED_PKL_ANNOTATION_TEXT_WITH_CPL,
341                 /** Some, but not all content, is encrypted */
342                 PARTIALLY_ENCRYPTED,
343                 /** General error during JPEG2000 codestream verification
344                  *  frame contains the frame index (counted from 0)
345                  *  note contains details
346                  */
347                 INVALID_JPEG2000_CODESTREAM,
348                 /** Invalid number of guard bits in a 2K JPEG2000 stream (should be 1) [Bv2.1_10.2.1]
349                  *  note contains the number of guard bits
350                  */
351                 INVALID_JPEG2000_GUARD_BITS_FOR_2K,
352                 /** Invalid number of guard bits in a 4K JPEG2000 stream (should be 2) [Bv2.1_10.2.1]
353                  *  note contains the number of guard bits
354                  */
355                 INVALID_JPEG2000_GUARD_BITS_FOR_4K,
356                 /** JPEG2000 tile size is not the same as the image size [Bv2.1_10.2.1] */
357                 INVALID_JPEG2000_TILE_SIZE,
358                 /** JPEG2000 code block width is not 32 [Bv2.1_10.2.1]
359                  *  note contains the code block width
360                  */
361                 INVALID_JPEG2000_CODE_BLOCK_WIDTH,
362                 /** JPEG2000 code block height is not 32 [Bv2.1_10.2.1]
363                  *  note contains the code block height
364                  */
365                 INVALID_JPEG2000_CODE_BLOCK_HEIGHT,
366                 /** There must be no POC markers in a 2K codestream [Bv2.1_10.2.1]
367                  *  note contains the number of POC markers found
368                  */
369                 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_2K,
370                 /** There must be exactly one POC marker in a 4K codestream [Bv2.1_10.2.1]
371                  *  note contains the number of POC markers found
372                  */
373                 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_4K,
374                 /** A POC marker has incorrect content [Bv2.1_10.2.1]
375                  *  note contains details
376                  */
377                 INCORRECT_JPEG2000_POC_MARKER,
378                 /** A POC marker was found outside the main head [Bv2.1_10.2.1] */
379                 INVALID_JPEG2000_POC_MARKER_LOCATION,
380                 /** Invalid number of tile parts for 2K JPEG2000 stream (should be 3) [Bv2.1_10.2.1]
381                  *  note contains the number of tile parts
382                  */
383                 INVALID_JPEG2000_TILE_PARTS_FOR_2K,
384                 /** Invalid number of tile parts for 4K JPEG2000 stream (should be 6) [Bv2.1_10.2.1]
385                  *  note contains the number of tile parts
386                  */
387                 INVALID_JPEG2000_TILE_PARTS_FOR_4K,
388                 /** No TLM marker was found [Bv2.1_10.2.1] */
389                 MISSING_JPEG200_TLM_MARKER,
390                 /** The MXF _ResourceID_ of a timed text resource was not the same as that of the contained XML essence [Bv2.1_10.4.3] */
391                 MISMATCHED_TIMED_TEXT_RESOURCE_ID,
392                 /** The AssetID of a timed text MXF is the same as its _ResourceID_ or that of the contained XML essence [Bv2.1_10.4.2] */
393                 INCORRECT_TIMED_TEXT_ASSET_ID,
394                 /** The ContainerDuration of a timed text MXF is not the same as the _Duration_ in its reel [Bv2.1_10.4.3]
395                  *  note contains the reel duration, followed by a space, followed by the MXF duration
396                  *  file contains the asset filename
397                  */
398                 MISMATCHED_TIMED_TEXT_DURATION,
399                 /** Something could not be verified because content is encrypted and no key is available */
400                 MISSED_CHECK_OF_ENCRYPTED,
401                 /** Some timed-text XML has an empty <_Text_> node */
402                 EMPTY_TEXT,
403                 /** Some closed captions do not have the same vertical alignment within a <_Subtitle_> node */
404                 MISMATCHED_CLOSED_CAPTION_VALIGN,
405                 /** Some closed captions are not listed in the XML in the order of their vertical position */
406                 INCORRECT_CLOSED_CAPTION_ORDERING,
407                 /** Some <MainMarkers> asset has an <EntryPoint> that should not be there */
408                 UNEXPECTED_ENTRY_POINT,
409                 /** Some <MainMarkers> asset has an <Duration> that should not be there */
410                 UNEXPECTED_DURATION,
411                 /** A <ContentKind> has been specified with either no scope or the SMPTE 429-7 scope, but which is not one of those allowed */
412                 INVALID_CONTENT_KIND,
413                 /** Either the width or height of a <MainPictureActiveArea> in a CPL is either not an even number, or bigger than the corresponding asset dimension.
414                  *  note contains details of what is wrong
415                  *  file contains the CPL filename
416                  */
417                 INVALID_MAIN_PICTURE_ACTIVE_AREA,
418                 /** A PKL has more than one asset with the same ID
419                  *  note contains the PKL ID
420                  *  file contains the PKL filename
421                  */
422                 DUPLICATE_ASSET_ID_IN_PKL,
423                 /** An ASSETMAP has more than one asset with the same ID
424                  *  note contains the ASSETMAP ID
425                  *  file contains the ASSETMAP filename
426                  */
427                 DUPLICATE_ASSET_ID_IN_ASSETMAP,
428                 /** An Interop subtitle asset has no subtitles
429                  *  note contains the asset ID
430                  *  file contains the asset filename
431                  */
432                 MISSING_SUBTITLE,
433                 /** A SMPTE subtitle asset as an <IssueDate> which is not of the form yyyy-mm-ddThh:mm:ss
434                  *  I can find no reference in a standard to this being required, but the Deluxe delivery
435                  *  specifications require it and their QC will fail DCPs that don't have it.
436                  *  note contains the incorrect <IssueDate>
437                  */
438                 INVALID_SUBTITLE_ISSUE_DATE,
439                 /** The sound assets in the CPL do not have the same audio channel count.
440                  *  file contains the filename of the first asset to differ
441                  */
442                 MISMATCHED_SOUND_CHANNEL_COUNTS,
443                 /** The CPL contains a MainSoundConfiguration tag which does not describe the number of
444                  *  channels in the audio assets.
445                  *  note contains details of what is wrong
446                  *  file contains the CPL filename
447                  */
448                 INVALID_MAIN_SOUND_CONFIGURATION,
449                 /** An interop subtitle file has a <LoadFont> node which refers to a font file that is not found.
450                  *  note contains the <LoadFont> ID
451                  */
452                 MISSING_FONT,
453                 /** A tile part in a JPEG2000 frame is too big.
454                  *  frame contains the frame index (counted from 0)
455                  *  component contains the component index (0, 1 or 2)
456                  *  size contains the invalid size in bytes.
457                  */
458                 INVALID_JPEG2000_TILE_PART_SIZE,
459                 /** A subtitle XML root node has more than one namespace (xmlns) declaration.
460                  *  note contains the asset ID
461                  */
462                 INCORRECT_SUBTITLE_NAMESPACE_COUNT,
463                 /** A subtitle or closed caption file has a <Font> tag which refers to a font that is not
464                  *  first introduced with a <LoadFont>.
465                  *  id contains the ID of the <Font> tag.
466                  */
467                 MISSING_LOAD_FONT_FOR_FONT,
468                 /** A SMPTE subtitle asset has at least one <Text> element but no <LoadFont>
469                  *  id contains the ID of the subtitle asset.
470                  */
471                 MISSING_LOAD_FONT,
472                 /** An ID in an asset map does not match the ID obtained from reading the actual file.
473                  *  id contains the ID from the asset map.
474                  *  other_id contains the ID from the file.
475                  */
476                 MISMATCHED_ASSET_MAP_ID,
477                 /** The <LabelText> inside a <ContentVersion> is empty
478                  *  note contains the CPL ID
479                  *  file contains the CPL filename
480                  */
481                 EMPTY_CONTENT_VERSION_LABEL_TEXT,
482         };
483
484         VerificationNote (Type type, Code code)
485                 : _type (type)
486                 , _code (code)
487         {}
488
489         VerificationNote (Type type, Code code, std::string note)
490                 : _type (type)
491                 , _code (code)
492         {
493                 _data[Data::NOTE] = note;
494         }
495
496         VerificationNote (Type type, Code code, boost::filesystem::path file)
497                 : _type (type)
498                 , _code (code)
499         {
500                 _data[Data::FILE] = file;
501         }
502
503         VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file)
504                 : _type (type)
505                 , _code (code)
506         {
507                 _data[Data::NOTE] = note;
508                 _data[Data::FILE] = file;
509         }
510
511         VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line)
512                 : _type (type)
513                 , _code (code)
514         {
515                 _data[Data::NOTE] = note;
516                 _data[Data::FILE] = file;
517                 _data[Data::LINE] = line;
518         }
519
520         Type type () const {
521                 return _type;
522         }
523
524         Code code () const {
525                 return _code;
526         }
527
528 private:
529         enum class Data {
530                 NOTE,  ///< further information about the error
531                 FILE,  ///< path of file containing the error
532                 LINE,  ///< error line number within the FILE
533                 FRAME,
534                 COMPONENT,
535                 SIZE,
536                 ID,
537                 OTHER_ID,
538                 FRAME_RATE,
539                 CPL_ID,
540                 CALCULATED_HASH,
541                 REFERENCE_HASH
542         };
543
544         template <class T>
545         boost::optional<T> data(Data key) const
546         {
547                 auto iter = _data.find(key);
548                 if (iter == _data.end()) {
549                         return {};
550                 }
551                 return boost::any_cast<T>(iter->second);
552         }
553
554 public:
555         boost::optional<std::string> note () const {
556                 return data<std::string>(Data::NOTE);
557         }
558
559         boost::optional<boost::filesystem::path> file () const {
560                 return data<boost::filesystem::path>(Data::FILE);
561         }
562
563         boost::optional<uint64_t> line () const {
564                 return data<uint64_t>(Data::LINE);
565         }
566
567         VerificationNote& set_frame(int frame) {
568                 _data[Data::FRAME] = frame;
569                 return *this;
570         }
571
572         boost::optional<int> frame() const {
573                 return data<int>(Data::FRAME);
574         }
575
576         VerificationNote& set_component(int component) {
577                 _data[Data::COMPONENT] = component;
578                 return *this;
579         }
580
581         boost::optional<int> component() const {
582                 return data<int>(Data::COMPONENT);
583         }
584
585         VerificationNote& set_size(int size) {
586                 _data[Data::SIZE] = size;
587                 return *this;
588         }
589
590         boost::optional<int> size() const {
591                 return data<int>(Data::SIZE);
592         }
593
594         VerificationNote& set_id(std::string id) {
595                 _data[Data::ID] = id;
596                 return *this;
597         }
598
599         boost::optional<std::string> id() const {
600                 return data<std::string>(Data::ID);
601         }
602
603         VerificationNote& set_other_id(std::string other_id) {
604                 _data[Data::OTHER_ID] = other_id;
605                 return *this;
606         }
607
608         boost::optional<std::string> other_id() const {
609                 return data<std::string>(Data::OTHER_ID);
610         }
611
612         VerificationNote& set_frame_rate(int frame_rate) {
613                 _data[Data::FRAME_RATE] = frame_rate;
614                 return *this;
615         }
616
617         boost::optional<int> frame_rate() const {
618                 return data<int>(Data::FRAME_RATE);
619         }
620
621         VerificationNote& set_calculated_hash(std::string hash) {
622                 _data[Data::CALCULATED_HASH] = hash;
623                 return *this;
624         }
625
626         boost::optional<std::string> calculated_hash() const {
627                 return data<std::string>(Data::CALCULATED_HASH);
628         }
629
630         VerificationNote& set_reference_hash(std::string hash) {
631                 _data[Data::REFERENCE_HASH] = hash;
632                 return *this;
633         }
634
635         boost::optional<std::string> reference_hash() const {
636                 return data<std::string>(Data::REFERENCE_HASH);
637         }
638
639         VerificationNote& set_cpl_id(std::string id) {
640                 _data[Data::CPL_ID] = id;
641                 return *this;
642         }
643
644         boost::optional<std::string> cpl_id() const {
645                 return data<std::string>(Data::CPL_ID);
646         }
647
648 private:
649         Type _type;
650         Code _code;
651         std::map<Data, boost::any> _data;
652 };
653
654
655 struct VerificationOptions
656 {
657         ///< If set, any assets larger than this number of bytes will not have their hashes checked
658         boost::optional<boost::uintmax_t> maximum_asset_size_for_hash_check;
659         ///< true to check asset hashes (except those which match maximum_asset_size_for_hash_check)
660         ///< false to check no asset hashes.
661         bool check_asset_hashes = true;
662 };
663
664
665 struct VerifyResult
666 {
667         std::vector<VerificationNote> notes;
668         std::vector<std::shared_ptr<dcp::DCP>> dcps;
669 };
670
671
672 VerifyResult verify(
673         std::vector<boost::filesystem::path> directories,
674         std::vector<dcp::DecryptedKDM> kdms,
675         std::function<void (std::string, boost::optional<boost::filesystem::path>)> stage,
676         std::function<void (float)> progress,
677         VerificationOptions options = {},
678         boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>()
679         );
680
681 std::string note_to_string (dcp::VerificationNote note);
682
683 bool operator== (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
684 bool operator!=(dcp::VerificationNote const& a, dcp::VerificationNote const& b);
685 bool operator< (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
686
687 std::ostream& operator<<(std::ostream& s, dcp::VerificationNote const& note);
688
689
690 }
691
692
693 #endif