diff --git a/include/fc/time.hpp b/include/fc/time.hpp index 34a635b..595e7d7 100644 --- a/include/fc/time.hpp +++ b/include/fc/time.hpp @@ -37,6 +37,10 @@ namespace fc { inline microseconds hours(int64_t h) { return minutes(60*h); } inline microseconds days(int64_t d) { return hours(24*d); } + class variant; + void to_variant( const fc::microseconds&, fc::variant& ); + void from_variant( const fc::variant& , fc::microseconds& ); + class time_point { public: explicit time_point( microseconds e = microseconds() ) :elapsed(e){} diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index fea92b2..cb49453 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -29,6 +29,7 @@ namespace fc class mutable_variant_object; class time_point; class time_point_sec; + class microseconds; void to_variant( const int16_t& var, variant& vo ); void from_variant( const variant& var, int16_t& vo ); @@ -69,6 +70,10 @@ namespace fc void to_variant( const time_point_sec& var, variant& vo ); void from_variant( const variant& var, time_point_sec& vo ); + + void to_variant( const microseconds& input_microseconds, variant& output_variant ); + void from_variant( const variant& input_variant, microseconds& output_microseconds ); + #ifdef __APPLE__ void to_variant( size_t s, variant& v ); #elif !defined(_MSC_VER) diff --git a/src/io/json.cpp b/src/io/json.cpp index e96cb25..b1a308d 100644 --- a/src/io/json.cpp +++ b/src/io/json.cpp @@ -132,6 +132,11 @@ namespace fc { return token.str(); } + catch (const std::ios_base::failure&) + { + return token.str(); + } + FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'", ("token", token.str() ) ); } @@ -179,6 +184,10 @@ namespace fc catch( const fc::eof_exception& e ) { FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) ); + } + catch( const std::ios_base::failure& e ) + { + FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.what() ) ); } FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" ); } @@ -261,6 +270,9 @@ namespace fc catch (fc::eof_exception&) { } + catch (const std::ios_base::failure&) + { + } fc::string str = ss.str(); if (str == "-." || str == ".") // check the obviously wrong things we could have encountered FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str)); @@ -306,6 +318,10 @@ namespace fc { received_eof = true; } + catch (const std::ios_base::failure&) + { + received_eof = true; + } // we can get here either by processing a delimiter as in "null," // an EOF like "null", or an invalid token like "nullZ" @@ -391,11 +407,11 @@ namespace fc return variant(); } variant json::from_string( const std::string& utf8_str ) - { - std::stringstream in( utf8_str ); - in.exceptions( std::ifstream::eofbit ); + { try { + fc::stringstream in( utf8_str ); + //in.exceptions( std::ifstream::eofbit ); return variant_from_stream( in ); - } + } FC_RETHROW_EXCEPTIONS( warn, "", ("str",utf8_str) ) } /* void toUTF8( const char str, ostream& os ) diff --git a/src/network/http/http_connection.cpp b/src/network/http/http_connection.cpp index 7921bf0..79433c7 100644 --- a/src/network/http/http_connection.cpp +++ b/src/network/http/http_connection.cpp @@ -8,6 +8,7 @@ #include #include #include +#include class fc::http::connection::impl @@ -55,7 +56,7 @@ class fc::http::connection::impl while( *end != '\r' ) ++end; h.val = fc::string(skey,end); rep.headers.push_back(h); - if( h.key == "Content-Length" ) { + if( boost::iequals(h.key, "Content-Length") ) { rep.body.resize( static_cast(to_uint64( fc::string(h.val) ) )); } } @@ -151,12 +152,12 @@ http::request connection::read_request()const { while( *end != '\r' ) ++end; h.val = fc::string(skey,end); req.headers.push_back(h); - if( h.key == "Content-Length" ) { + if( boost::iequals(h.key, "Content-Length")) { auto s = static_cast(to_uint64( fc::string(h.val) ) ); FC_ASSERT( s < 1024*1024 ); req.body.resize( static_cast(to_uint64( fc::string(h.val) ) )); } - if( h.key == "Host" ) { + if( boost::iequals(h.key, "Host") ) { req.domain = h.val; } } diff --git a/src/time.cpp b/src/time.cpp index da333cc..0586151 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -99,4 +99,14 @@ namespace fc { string get_approximate_relative_time_string(const time_point& event_time) { return get_approximate_relative_time_string(time_point_sec(event_time)); } -} + + void to_variant( const microseconds& input_microseconds, variant& output_variant ) + { + output_variant = input_microseconds.count(); + } + void from_variant( const variant& input_variant, microseconds& output_microseconds ) + { + output_microseconds = microseconds(input_variant.as_int64()); + } + +} //namespace fc