Use locked_sstream. Replace once parse_stream with parse_memory.
authorCarl Hetherington <cth@carlh.net>
Fri, 22 Jul 2016 08:20:58 +0000 (09:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 22 Jul 2016 08:20:58 +0000 (09:20 +0100)
12 files changed:
cscript
src/certificate.cc
src/certificate_chain.cc
src/compose.hpp
src/dcp_time.cc
src/decrypted_kdm.cc
src/key.cc
src/raw_convert.h
src/types.cc
test/colour_test.cc
test/kdm_test.cc
test/test.cc

diff --git a/cscript b/cscript
index d2375c40086051fd1f97d96145d234d517c06aa0..43f47e33fb2678e1396ac47700cc4522aedef1f2 100644 (file)
--- a/cscript
+++ b/cscript
@@ -35,9 +35,9 @@ import os
 
 def dependencies(target):
     if target.platform == 'windows' and target.version == 'xp':
-        return (('libcxml', 'v0.15.1'), ('openjpeg-cdist',  '5d8bffd'), ('asdcplib-cth', 'v0.1.2'))
+        return (('libcxml', 'b08e6b4'), ('openjpeg-cdist',  '5d8bffd'), ('asdcplib-cth', 'v0.1.2'))
     else:
-        return (('libcxml', 'v0.15.1'), ('openjpeg2-cdist', '94bdab1'), ('asdcplib-cth', 'v0.1.2'))
+        return (('libcxml', 'b08e6b4'), ('openjpeg2-cdist', '94bdab1'), ('asdcplib-cth', 'v0.1.2'))
 
 def build(target, options):
     cmd = './waf configure --disable-examples --prefix=%s' % target.directory
index 18249a58aa26595f1ffcbd29e69424ce8a77128e..34f797545cad3cb379b0ef1219012d9f58105fe9 100644 (file)
@@ -55,7 +55,6 @@ using std::list;
 using std::string;
 using std::ostream;
 using std::min;
-using std::stringstream;
 using namespace dcp;
 
 static string const begin_certificate = "-----BEGIN CERTIFICATE-----";
@@ -104,7 +103,7 @@ Certificate::read_string (string cert)
           See http://comments.gmane.org/gmane.comp.encryption.openssl.user/55593
        */
 
-       stringstream s (cert);
+       locked_stringstream s (cert);
        string line;
 
        /* BEGIN */
index 0046fe757e07eaf453be3320b2790ee524474f8a..2ba701838723e41b29de4e59347d08b66e8588cf 100644 (file)
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
 #include <fstream>
-#include <sstream>
 
 using std::string;
 using std::ofstream;
 using std::ifstream;
 using std::runtime_error;
-using std::stringstream;
 using namespace dcp;
 
 /** Run a shell command.
@@ -108,7 +106,7 @@ command (string cmd)
        int const code = WEXITSTATUS (r);
 #endif
        if (code) {
-               stringstream s;
+               locked_stringstream s;
                s << "error " << code << " in " << cmd << " within " << boost::filesystem::current_path();
                throw dcp::MiscError (s.str());
        }
@@ -125,7 +123,7 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        boost::filesystem::path public_name = private_key.string() + ".public";
 
        /* Create the public key from the private key */
-       stringstream s;
+       locked_stringstream s;
        s << "\"" << openssl.string() << "\" rsa -outform PEM -pubout -in " << private_key.string() << " -out " << public_name.string ();
        command (s.str().c_str ());
 
@@ -222,7 +220,7 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("ca.key", openssl);
 
        {
-               stringstream c;
+               locked_stringstream c;
                c << quoted_openssl
                  << " req -new -x509 -sha256 -config ca.cnf -days 3650 -set_serial 5"
                  << " -subj \"" << ca_subject << "\" -key ca.key -outform PEM -out ca.self-signed.pem";
@@ -253,7 +251,7 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("intermediate.key", openssl);
 
        {
-               stringstream s;
+               locked_stringstream s;
                s << quoted_openssl
                  << " req -new -config intermediate.cnf -days 3649 -subj \"" << inter_subject << "\" -key intermediate.key -out intermediate.csr";
                command (s.str().c_str());
@@ -290,7 +288,7 @@ CertificateChain::CertificateChain (
                "/dnQualifier=" + public_key_digest ("leaf.key", openssl);
 
        {
-               stringstream s;
+               locked_stringstream s;
                s << quoted_openssl << " req -new -config leaf.cnf -days 3648 -subj \"" << leaf_subject << "\" -key leaf.key -outform PEM -out leaf.csr";
                command (s.str().c_str());
        }
index f7bd4282fb398c901db8091697ffa5db772a43c1..185e00a4de64c24eaf8bbd129b71835caf2f6461 100644 (file)
@@ -33,7 +33,7 @@
 #ifndef STRING_COMPOSE_H
 #define STRING_COMPOSE_H
 
-#include <sstream>
+#include <locked_sstream.h>
 #include <string>
 #include <list>
 #include <map>                 // for multimap
@@ -58,7 +58,7 @@ namespace StringPrivate
     std::string str() const;
 
   private:
-    std::ostringstream os;
+    locked_stringstream os;
     int arg_no;
 
     // we store the output as a list - when the output string is requested, the
@@ -106,7 +106,7 @@ namespace StringPrivate
     case '8':
     case '9':
       return true;
-    
+
     default:
       return false;
     }
@@ -120,21 +120,21 @@ namespace StringPrivate
     os << obj;
 
     std::string rep = os.str();
-  
+
     if (!rep.empty()) {                // manipulators don't produce output
       for (specification_map::const_iterator i = specs.lower_bound(arg_no),
             end = specs.upper_bound(arg_no); i != end; ++i) {
        output_list::iterator pos = i->second;
        ++pos;
-      
+
        output.insert(pos, rep);
       }
-    
+
       os.str(std::string());
       //os.clear();
       ++arg_no;
     }
-  
+
     return *this;
   }
 
@@ -142,7 +142,7 @@ namespace StringPrivate
     : arg_no(1)
   {
     std::string::size_type b = 0, i = 0;
-  
+
     // fill in output with the strings between the %1 %2 %3 etc. and
     // fill in specs with the positions
     while (i < fmt.length()) {
@@ -154,7 +154,7 @@ namespace StringPrivate
        else if (is_number(fmt[i + 1])) { // aha! a spec!
          // save string
          output.push_back(fmt.substr(b, i - b));
-       
+
          int n = 1;            // number of digits
          int spec_no = 0;
 
@@ -167,9 +167,9 @@ namespace StringPrivate
          spec_no /= 10;
          output_list::iterator pos = output.end();
          --pos;                // safe since we have just inserted a string>
-       
+
          specs.insert(specification_map::value_type(spec_no, pos));
-       
+
          // jump over spec string
          i += n;
          b = i;
@@ -180,7 +180,7 @@ namespace StringPrivate
       else
        ++i;
     }
-  
+
     if (i - b > 0)             // add the rest of the string
       output.push_back(fmt.substr(b, i - b));
   }
@@ -189,17 +189,17 @@ namespace StringPrivate
   {
     // assemble string
     std::string str;
-  
+
     for (output_list::const_iterator i = output.begin(), end = output.end();
         i != end; ++i)
       str += *i;
-  
+
     return str;
   }
 }
 
 // now for the real thing(s)
-namespace String 
+namespace String
 {
   // a series of functions which accept a format string on the form "text %1
   // more %2 less %3" and a number of templated parameters and spits out the
@@ -310,7 +310,7 @@ namespace String
       .arg(o10);
     return c.str();
   }
-  
+
   template <typename T1, typename T2, typename T3, typename T4, typename T5,
            typename T6, typename T7, typename T8, typename T9, typename T10,
            typename T11>
index 401abb3c397c96790030696d43ea2c9bb4eae420..526c784c95b09bff127aba1900d501281972a5d6 100644 (file)
@@ -330,7 +330,7 @@ dcp::operator/ (Time a, Time const & b)
 string
 Time::as_string (Standard standard) const
 {
-       stringstream str;
+       locked_stringstream str;
        str << setw(2) << setfill('0') << h << ":"
            << setw(2) << setfill('0') << m << ":"
            << setw(2) << setfill('0') << s << ":";
index abe12a324da2f837e095913ba4d92c2c05db7ad7..4ffad92323c2a820c1120c663ca4e9fcc48d9f79 100644 (file)
@@ -52,7 +52,6 @@
 using std::list;
 using std::vector;
 using std::string;
-using std::stringstream;
 using std::setw;
 using std::setfill;
 using std::hex;
@@ -79,7 +78,7 @@ put_uuid (uint8_t ** d, string id)
 {
         id.erase (std::remove (id.begin(), id.end(), '-'));
         for (int i = 0; i < 32; i += 2) {
-                stringstream s;
+                locked_stringstream s;
                 s << id[i] << id[i + 1];
                 int h;
                 s >> hex >> h;
@@ -91,7 +90,7 @@ put_uuid (uint8_t ** d, string id)
 static string
 get_uuid (unsigned char ** p)
 {
-       stringstream g;
+       locked_stringstream g;
 
        for (int i = 0; i < 16; ++i) {
                g << setw(2) << setfill('0') << hex << static_cast<int> (**p);
@@ -301,7 +300,7 @@ DecryptedKDM::encrypt (shared_ptr<const CertificateChain> signer, Certificate re
                char out[encrypted_len * 2];
                Kumu::base64encode (encrypted, encrypted_len, out, encrypted_len * 2);
                int const N = strlen (out);
-               stringstream lines;
+               locked_stringstream lines;
                for (int i = 0; i < N; ++i) {
                        if (i > 0 && (i % 64) == 0) {
                                lines << "\n";
index d2417a0956901387c450d3b6a2ee5a6bdac738a2..cf7b4d6d720a25acdfadf275aadbd450f02f4070 100644 (file)
  */
 
 #include "key.h"
+#include <locked_sstream.h>
 #include <asdcp/AS_DCP.h>
 #include <asdcp/KM_prng.h>
 #include <asdcp/KM_util.h>
-#include <sstream>
 #include <string>
 #include <iomanip>
 
 using std::string;
-using std::stringstream;
 using std::setw;
 using std::setfill;
 using namespace dcp;
@@ -94,7 +93,7 @@ Key::operator= (Key const & other)
 string
 Key::hex () const
 {
-       stringstream g;
+       locked_stringstream g;
 
        for (unsigned int i = 0; i < ASDCP::KeyLen; ++i) {
                g << setw(2) << setfill('0') << std::hex << static_cast<int> (_value[i]);
index 36d578b40c383ca0da314b02b10478ab5fc783ec..5fc05c12257e3d65204c69dfde971d063eadf39b 100644 (file)
@@ -34,7 +34,7 @@
 #ifndef LIBDCP_RAW_CONVERT_H
 #define LIBDCP_RAW_CONVERT_H
 
-#include <sstream>
+#include <locked_sstream.h>
 #include <iomanip>
 
 namespace dcp {
@@ -46,7 +46,7 @@ template <typename P, typename Q>
 P
 raw_convert (Q v, int precision = 16, bool fixed = false)
 {
-       std::stringstream s;
+       locked_stringstream s;
        s.imbue (std::locale::classic ());
        s << std::setprecision (precision);
        if (fixed) {
index cbb56e7fe2f0ebbf157523b218ab2590ff04f363..cf3229dfcb00d24fb4dd07798f7a8f6a085cb3c7 100644 (file)
@@ -121,7 +121,7 @@ Colour::Colour (string argb_hex)
 string
 Colour::to_argb_string () const
 {
-       stringstream s;
+       locked_stringstream s;
        s << "FF";
        s << hex
          << setw(2) << setfill('0') << r
index a99b5b7ef4ab701ec9bcc5f5b0b5d558edfbf566..d39c888daeafb6b58e0e547c38c3947ac43b750a 100644 (file)
 
 #include "util.h"
 #include "exceptions.h"
+#include <locked_sstream.h>
 #include <boost/test/unit_test.hpp>
 
-using std::stringstream;
-
 /** Check that dcp::Colour works */
 BOOST_AUTO_TEST_CASE (colour)
 {
@@ -58,7 +57,7 @@ BOOST_AUTO_TEST_CASE (colour)
 
        BOOST_CHECK_THROW (dcp::Colour ("001234"), dcp::XMLError);
 
-       stringstream s;
+       locked_stringstream s;
        s << c;
        BOOST_CHECK_EQUAL (s.str(), "(255, 0, 0)");
 }
index ee52ad8ebc207ce0c0f859385aa3a2b1db6d6c13..82701d96abf20c909daf0d727bb7ab26f0fb0b75 100644 (file)
     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <boost/test/unit_test.hpp>
-#include <libxml++/libxml++.h>
 #include "encrypted_kdm.h"
 #include "decrypted_kdm.h"
 #include "util.h"
+#include <libxml++/libxml++.h>
+#include <boost/test/unit_test.hpp>
 
 using std::list;
-using std::stringstream;
 using boost::shared_ptr;
 
 /** Check reading and decryption of a KDM */
@@ -58,9 +57,7 @@ BOOST_AUTO_TEST_CASE (kdm_passthrough_test)
                );
 
        shared_ptr<xmlpp::DomParser> parser (new xmlpp::DomParser ());
-       stringstream s;
-       s << kdm.as_xml ();
-       parser->parse_stream (s);
+       parser->parse_memory (kdm.as_xml ());
        parser->get_document()->write_to_file_formatted ("build/kdm.xml", "UTF-8");
        int const r = system (
                "xmldiff -c test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml build/kdm.xml"
index 0e7ad51178e356c638facd773bed9230794c095c..c17f1506fcc40036eb827573b6d356b1495be896 100644 (file)
 #define BOOST_TEST_MODULE libdcp_test
 #include "util.h"
 #include "test.h"
+#include <locked_sstream.h>
 #include <libxml++/libxml++.h>
 #include <boost/test/unit_test.hpp>
 #include <cstdio>
 
 using std::string;
 using std::min;
-using std::stringstream;
 using std::list;
 
 boost::filesystem::path private_test;
@@ -123,7 +123,7 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check)
        uint8_t* ref_buffer = new uint8_t[buffer_size];
        uint8_t* check_buffer = new uint8_t[buffer_size];
 
-       stringstream error;
+       locked_stringstream error;
        error << "File " << check.string() << " differs from reference " << ref.string();
 
        while (N) {