Missing error checking on writing KDMs as XML.
[libdcp.git] / src / util.cc
index c7d090eaa016764411e8e44e935bc1a63d0a9c99..211f03f8ccda87742a7532c1ad03368026bcb555 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
@@ -36,6 +36,7 @@
  */
 
 #include "util.h"
+#include "language_tag.h"
 #include "exceptions.h"
 #include "types.h"
 #include "certificate.h"
@@ -76,6 +77,13 @@ using boost::function;
 using boost::algorithm::trim;
 using namespace dcp;
 
+
+/* Some ASDCP objects store this as a *&, for reasons which are not
+ * at all clear, so we have to keep this around forever.
+ */
+ASDCP::Dictionary const* dcp::asdcp_smpte_dict = 0;
+
+
 /** Create a UUID.
  *  @return UUID.
  */
@@ -164,11 +172,15 @@ dcp::empty_or_white_space (string s)
        return true;
 }
 
-/** Set up various bits that the library needs.  Should be called one
+/** Set up various bits that the library needs.  Should be called once
  *  by client applications.
+ *
+ *  @param tags_directory Path to a copy of the tags directory from the source code;
+ *  if none is specified libdcp will look for a tags directory inside the environment
+ *  variable LIBDCP_SHARE_PREFIX or the LIBDCP_SHARE_PREFIX #defined during the build.
  */
 void
-dcp::init ()
+dcp::init (optional<boost::filesystem::path> tags_directory)
 {
        if (xmlSecInit() < 0) {
                throw MiscError ("could not initialise xmlsec");
@@ -189,6 +201,19 @@ dcp::init ()
        }
 
        OpenSSL_add_all_algorithms();
+
+       asdcp_smpte_dict = &ASDCP::DefaultSMPTEDict();
+
+       if (!tags_directory) {
+               char* prefix = getenv("LIBDCP_SHARE_PREFIX");
+               if (prefix) {
+                       tags_directory = boost::filesystem::path(prefix) / "tags";
+               } else {
+                       tags_directory = LIBDCP_SHARE_PREFIX "/tags";
+               }
+       }
+
+       load_language_tag_lists (*tags_directory);
 }
 
 /** Decode a base64 string.  The base64 decode routine in KM_util.cpp
@@ -443,4 +468,3 @@ ASDCPErrorSuspender::~ASDCPErrorSuspender ()
        delete _sink;
 }
 
-