From: Carl Hetherington Date: Fri, 22 Jul 2016 08:20:58 +0000 (+0100) Subject: Use locked_sstream. Replace once parse_stream with parse_memory. X-Git-Tag: v1.4.0~72^2~4 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=455475575bcfa30aa60a377235bfaf2fd7bc2da7;p=libdcp.git Use locked_sstream. Replace once parse_stream with parse_memory. --- diff --git a/cscript b/cscript index d2375c40..43f47e33 100644 --- 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 diff --git a/src/certificate.cc b/src/certificate.cc index 18249a58..34f79754 100644 --- a/src/certificate.cc +++ b/src/certificate.cc @@ -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 */ diff --git a/src/certificate_chain.cc b/src/certificate_chain.cc index 0046fe75..2ba70183 100644 --- a/src/certificate_chain.cc +++ b/src/certificate_chain.cc @@ -55,13 +55,11 @@ #include #include #include -#include 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()); } diff --git a/src/compose.hpp b/src/compose.hpp index f7bd4282..185e00a4 100644 --- a/src/compose.hpp +++ b/src/compose.hpp @@ -33,7 +33,7 @@ #ifndef STRING_COMPOSE_H #define STRING_COMPOSE_H -#include +#include #include #include #include // 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 diff --git a/src/dcp_time.cc b/src/dcp_time.cc index 401abb3c..526c784c 100644 --- a/src/dcp_time.cc +++ b/src/dcp_time.cc @@ -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 << ":"; diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc index abe12a32..4ffad923 100644 --- a/src/decrypted_kdm.cc +++ b/src/decrypted_kdm.cc @@ -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 (**p); @@ -301,7 +300,7 @@ DecryptedKDM::encrypt (shared_ptr 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"; diff --git a/src/key.cc b/src/key.cc index d2417a09..cf7b4d6d 100644 --- a/src/key.cc +++ b/src/key.cc @@ -36,15 +36,14 @@ */ #include "key.h" +#include #include #include #include -#include #include #include 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 (_value[i]); diff --git a/src/raw_convert.h b/src/raw_convert.h index 36d578b4..5fc05c12 100644 --- a/src/raw_convert.h +++ b/src/raw_convert.h @@ -34,7 +34,7 @@ #ifndef LIBDCP_RAW_CONVERT_H #define LIBDCP_RAW_CONVERT_H -#include +#include #include namespace dcp { @@ -46,7 +46,7 @@ template 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) { diff --git a/src/types.cc b/src/types.cc index cbb56e7f..cf3229df 100644 --- a/src/types.cc +++ b/src/types.cc @@ -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 diff --git a/test/colour_test.cc b/test/colour_test.cc index a99b5b7e..d39c888d 100644 --- a/test/colour_test.cc +++ b/test/colour_test.cc @@ -19,10 +19,9 @@ #include "util.h" #include "exceptions.h" +#include #include -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)"); } diff --git a/test/kdm_test.cc b/test/kdm_test.cc index ee52ad8e..82701d96 100644 --- a/test/kdm_test.cc +++ b/test/kdm_test.cc @@ -17,14 +17,13 @@ along with libdcp. If not, see . */ -#include -#include #include "encrypted_kdm.h" #include "decrypted_kdm.h" #include "util.h" +#include +#include 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 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" diff --git a/test/test.cc b/test/test.cc index 0e7ad511..c17f1506 100644 --- a/test/test.cc +++ b/test/test.cc @@ -21,13 +21,13 @@ #define BOOST_TEST_MODULE libdcp_test #include "util.h" #include "test.h" +#include #include #include #include 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) {