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