2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
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.
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.
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/>.
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
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.
36 * @brief Utility methods and classes
44 #include "array_data.h"
46 #include "local_time.h"
47 #include <asdcp/KM_log.h>
49 #include <boost/function.hpp>
50 #include <boost/filesystem.hpp>
51 #include <boost/optional.hpp>
56 #define LIBDCP_UNUSED(x) (void)(x)
68 class CertificateChain;
73 extern std::string make_uuid ();
75 /** Create a digest for a file
76 * @param filename File name
77 * @param progress Optional progress reporting function. The function will be called
78 * with a progress value between 0 and 1
81 extern std::string make_digest (boost::filesystem::path filename, boost::function<void (float)>);
83 extern std::string make_digest (ArrayData data);
86 * @return true if the string contains only space, newline or tab characters, or is empty
88 extern bool empty_or_white_space (std::string s);
90 extern bool ids_equal (std::string a, std::string b);
91 extern std::string remove_urn_uuid (std::string raw);
93 /** Set up various bits that the library needs. Should be called once
94 * by client applications.
96 * @param tags_directory Path to a copy of the tags directory from the source code;
97 * if none is specified libdcp will look for a tags directory inside the environment
98 * variable LIBDCP_SHARE_PREFIX or the LIBDCP_SHARE_PREFIX #defined during the build.
100 extern void init (boost::optional<boost::filesystem::path> tags_directory = boost::optional<boost::filesystem::path>());
102 /** Decode a base64 string. The base64 decode routine in KM_util.cpp
103 * gives different values to both this and the command-line base64
104 * for some inputs. Not sure why.
106 * @param in base64-encoded string
107 * @param out Output buffer
108 * @param out_length Length of output buffer
109 * @return Number of characters written to the output buffer
111 extern int base64_decode (std::string const & in, unsigned char* out, int out_length);
113 extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesystem::path root, boost::filesystem::path file);
115 /** @param p Path to open
116 * @param t mode flags, as for fopen(3)
117 * @return FILE pointer or 0 on error
119 * Apparently there is no way to create an ofstream using a UTF-8
120 * filename under Windows. We are hence reduced to using fopen
123 extern FILE * fopen_boost (boost::filesystem::path, std::string);
125 extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 1048576);
127 /** @param key RSA private key in PEM format (optionally with -----BEGIN... / -----END...)
128 * @return SHA1 fingerprint of key
130 extern std::string private_key_fingerprint (std::string key);
131 extern xmlpp::Node* find_child (xmlpp::Node const * node, std::string name);
132 extern std::string openjpeg_version();
133 extern std::string spaces (int n);
134 extern void indent (xmlpp::Element* element, int initial);
136 /** @return true if the day represented by \ref a is less than or
137 * equal to the one represented by \ref b, ignoring the time parts
139 extern bool day_less_than_or_equal (LocalTime a, LocalTime b);
141 /** @return true if the day represented by \ref a is greater than or
142 * equal to the one represented by \ref b, ignoring the time parts
144 extern bool day_greater_than_or_equal (LocalTime a, LocalTime b);
146 /** Try quite hard to find a string which starts with \ref base and is
147 * not in \ref existing
149 extern std::string unique_string (std::vector<std::string> existing, std::string base);
151 extern ASDCP::Dictionary const* asdcp_smpte_dict;
154 class ASDCPErrorSuspender
157 ASDCPErrorSuspender();
158 ~ASDCPErrorSuspender();
161 Kumu::LogEntryList _log;
162 Kumu::ILogSink& _old;
163 Kumu::EntryListLogSink* _sink;