Fully indent PKL/CPL.
authorCarl Hetherington <cth@carlh.net>
Tue, 22 Jan 2019 00:40:16 +0000 (00:40 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 24 Jan 2019 02:03:05 +0000 (02:03 +0000)
src/certificate_chain.cc
src/cpl.cc
src/pkl.cc
src/util.cc
src/util.h

index ebc3cc7ff215d5e2691a296f73fdaecc6e1dd1bd..353444faa308cc95bbc6d6cbfe6f1eaeb60cbc07 100644 (file)
@@ -552,33 +552,6 @@ CertificateChain::root_to_leaf () const
        throw CertificateChainError ("certificate chain is not consistent");
 }
 
-static string
-spaces (int n)
-{
-       string s = "";
-       for (int i = 0; i < n; ++i) {
-               s += " ";
-       }
-       return s;
-}
-
-static void
-indent (xmlpp::Element* element, int initial)
-{
-       xmlpp::Node* last = 0;
-       BOOST_FOREACH (xmlpp::Node * n, element->get_children()) {
-               xmlpp::Element* e = dynamic_cast<xmlpp::Element*>(n);
-               if (e) {
-                       element->add_child_text_before (e, "\n" + spaces(initial + 2));
-                       indent (e, initial + 2);
-                       last = n;
-               }
-       }
-       if (last) {
-               element->add_child_text (last, "\n" + spaces(initial));
-       }
-}
-
 /** Add a &lt;Signer&gt; and &lt;ds:Signature&gt; nodes to an XML node.
  *  @param parent XML node to add to.
  *  @param standard INTEROP or SMPTE.
index 4a594b5a477a305d65a2337ceadbe28f814b3f16..3eeb102c196b28ac83af9736ec1c997800ddded9 100644 (file)
@@ -164,6 +164,8 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
                i->write_to_cpl (reel_list, standard);
        }
 
+       indent (root, 0);
+
        if (signer) {
                signer->sign (root, standard);
        }
index 9910b1906f8241a4232ca1b26e40f46a2d6362ba..adcad573ccfbec5ac772e3cc1c4728ae4fd050a7 100644 (file)
@@ -109,6 +109,8 @@ PKL::write (boost::filesystem::path file, shared_ptr<const CertificateChain> sig
                asset->add_child("Type")->add_child_text (i->type);
        }
 
+       indent (pkl, 0);
+
        if (signer) {
                signer->sign (pkl, _standard);
        }
index df79fb26e1a3dc52dba989c3718889b0fc48715f..d5b6cb9f4eaeed6ccc33a493ea6766eac9389446 100644 (file)
@@ -55,6 +55,7 @@
 #include <openssl/sha.h>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/foreach.hpp>
 #include <stdexcept>
 #include <iostream>
 #include <iomanip>
@@ -348,3 +349,30 @@ dcp::openjpeg_version ()
 {
        return opj_version ();
 }
+
+string
+dcp::spaces (int n)
+{
+       string s = "";
+       for (int i = 0; i < n; ++i) {
+               s += " ";
+       }
+       return s;
+}
+
+void
+dcp::indent (xmlpp::Element* element, int initial)
+{
+       xmlpp::Node* last = 0;
+       BOOST_FOREACH (xmlpp::Node * n, element->get_children()) {
+               xmlpp::Element* e = dynamic_cast<xmlpp::Element*>(n);
+               if (e) {
+                       element->add_child_text_before (e, "\n" + spaces(initial + 2));
+                       indent (e, initial + 2);
+                       last = n;
+               }
+       }
+       if (last) {
+               element->add_child_text (last, "\n" + spaces(initial));
+       }
+}
index 2f3b810a0ae64975f501e276a2cef2117885a6df..bc109c62a8ee7185117945e315b857fac235b985 100644 (file)
@@ -73,6 +73,8 @@ extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length
 extern std::string private_key_fingerprint (std::string key);
 extern xmlpp::Node* find_child (xmlpp::Node const * node, std::string name);
 extern std::string openjpeg_version();
+extern std::string spaces (int n);
+extern void indent (xmlpp::Element* element, int initial);
 
 }