Skip to content

Commit 125bdea

Browse files
committed
Merge pull request #2740 from constantined/constantined
UTF-8 support for JSON-RPC
2 parents 8435f7b + 2ecb755 commit 125bdea

18 files changed

+697
-398
lines changed

src/bitcoinrpc.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ using namespace boost;
3131
using namespace boost::asio;
3232
using namespace json_spirit;
3333

34+
static const char* Value_type_name[]={"obj", "array", "str", "bool", "int", "real", "null"};
35+
3436
static std::string strRPCUserColonPass;
3537

3638
// These are created by StartRPCThreads, destroyed in StopRPCThreads
@@ -531,7 +533,7 @@ string JSONRPCRequest(const string& strMethod, const Array& params, const Value&
531533
request.push_back(Pair("method", strMethod));
532534
request.push_back(Pair("params", params));
533535
request.push_back(Pair("id", id));
534-
return write_string(Value(request), false) + "\n";
536+
return write_string(Value(request), raw_utf8) + "\n";
535537
}
536538

537539
Object JSONRPCReplyObj(const Value& result, const Value& error, const Value& id)
@@ -549,7 +551,7 @@ Object JSONRPCReplyObj(const Value& result, const Value& error, const Value& id)
549551
string JSONRPCReply(const Value& result, const Value& error, const Value& id)
550552
{
551553
Object reply = JSONRPCReplyObj(result, error, id);
552-
return write_string(Value(reply), false) + "\n";
554+
return write_string(Value(reply), raw_utf8) + "\n";
553555
}
554556

555557
void ErrorReply(std::ostream& stream, const Object& objError, const Value& id)
@@ -980,7 +982,7 @@ static string JSONRPCExecBatch(const Array& vReq)
980982
for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
981983
ret.push_back(JSONRPCExecOne(vReq[reqIdx]));
982984

983-
return write_string(Value(ret), false) + "\n";
985+
return write_string(Value(ret), raw_utf8) + "\n";
984986
}
985987

986988
void ServiceConnection(AcceptedConnection *conn)
@@ -1282,7 +1284,7 @@ int CommandLineRPC(int argc, char *argv[])
12821284
if (error.type() != null_type)
12831285
{
12841286
// Error
1285-
strPrint = "error: " + write_string(error, false);
1287+
strPrint = "error: " + write_string(error, raw_utf8);
12861288
int code = find_value(error.get_obj(), "code").get_int();
12871289
nRet = abs(code);
12881290
}
@@ -1294,7 +1296,7 @@ int CommandLineRPC(int argc, char *argv[])
12941296
else if (result.type() == str_type)
12951297
strPrint = result.get_str();
12961298
else
1297-
strPrint = write_string(result, true);
1299+
strPrint = write_string(result, pretty_print | raw_utf8);
12981300
}
12991301
}
13001302
catch (boost::thread_interrupted) {

src/json/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2007 - 2009 John W. Wilkinson
3+
Copyright (c) 2007 - 2010 John W. Wilkinson
44

55
Permission is hereby granted, free of charge, to any person
66
obtaining a copy of this software and associated documentation

src/json/json_spirit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef JSON_SPIRIT
22
#define JSON_SPIRIT
33

4-
// Copyright John W. Wilkinson 2007 - 2009.
4+
// Copyright John W. Wilkinson 2007 - 2013
55
// Distributed under the MIT License, see accompanying file LICENSE.txt
66

7-
// json spirit version 4.03
7+
// json spirit version 4.06
88

99
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1010
# pragma once

src/json/json_spirit_error_position.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef JSON_SPIRIT_ERROR_POSITION
22
#define JSON_SPIRIT_ERROR_POSITION
33

4-
// Copyright John W. Wilkinson 2007 - 2009.
4+
// Copyright John W. Wilkinson 2007 - 2013
55
// Distributed under the MIT License, see accompanying file LICENSE.txt
66

7-
// json spirit version 4.03
7+
// json spirit version 4.06
88

99
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
1010
# pragma once
@@ -48,7 +48,7 @@ namespace json_spirit
4848
return ( reason_ == lhs.reason_ ) &&
4949
( line_ == lhs.line_ ) &&
5050
( column_ == lhs.column_ );
51-
}
51+
}
5252
}
5353

5454
#endif

src/json/json_spirit_reader.cpp

Lines changed: 124 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,137 @@
1-
// Copyright John W. Wilkinson 2007 - 2009.
1+
// Copyright John W. Wilkinson 2007 - 2013
22
// Distributed under the MIT License, see accompanying file LICENSE.txt
33

4-
// json spirit version 4.03
4+
// json spirit version 4.06
55

66
#include "json_spirit_reader.h"
77
#include "json_spirit_reader_template.h"
88

99
using namespace json_spirit;
1010

11-
bool json_spirit::read( const std::string& s, Value& value )
12-
{
13-
return read_string( s, value );
14-
}
15-
16-
void json_spirit::read_or_throw( const std::string& s, Value& value )
17-
{
18-
read_string_or_throw( s, value );
19-
}
20-
21-
bool json_spirit::read( std::istream& is, Value& value )
22-
{
23-
return read_stream( is, value );
24-
}
25-
26-
void json_spirit::read_or_throw( std::istream& is, Value& value )
27-
{
28-
read_stream_or_throw( is, value );
29-
}
30-
31-
bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, Value& value )
32-
{
33-
return read_range( begin, end, value );
34-
}
35-
36-
void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, Value& value )
37-
{
38-
begin = read_range_or_throw( begin, end, value );
39-
}
40-
41-
#ifndef BOOST_NO_STD_WSTRING
42-
43-
bool json_spirit::read( const std::wstring& s, wValue& value )
44-
{
45-
return read_string( s, value );
46-
}
47-
48-
void json_spirit::read_or_throw( const std::wstring& s, wValue& value )
49-
{
50-
read_string_or_throw( s, value );
51-
}
52-
53-
bool json_spirit::read( std::wistream& is, wValue& value )
54-
{
55-
return read_stream( is, value );
56-
}
57-
58-
void json_spirit::read_or_throw( std::wistream& is, wValue& value )
59-
{
60-
read_stream_or_throw( is, value );
61-
}
62-
63-
bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value )
64-
{
65-
return read_range( begin, end, value );
66-
}
67-
68-
void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value )
69-
{
70-
begin = read_range_or_throw( begin, end, value );
71-
}
11+
#ifdef JSON_SPIRIT_VALUE_ENABLED
12+
bool json_spirit::read( const std::string& s, Value& value )
13+
{
14+
return read_string( s, value );
15+
}
16+
17+
void json_spirit::read_or_throw( const std::string& s, Value& value )
18+
{
19+
read_string_or_throw( s, value );
20+
}
21+
22+
bool json_spirit::read( std::istream& is, Value& value )
23+
{
24+
return read_stream( is, value );
25+
}
26+
27+
void json_spirit::read_or_throw( std::istream& is, Value& value )
28+
{
29+
read_stream_or_throw( is, value );
30+
}
31+
32+
bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, Value& value )
33+
{
34+
return read_range( begin, end, value );
35+
}
36+
37+
void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, Value& value )
38+
{
39+
begin = read_range_or_throw( begin, end, value );
40+
}
41+
#endif
7242

43+
#if defined( JSON_SPIRIT_WVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
44+
bool json_spirit::read( const std::wstring& s, wValue& value )
45+
{
46+
return read_string( s, value );
47+
}
48+
49+
void json_spirit::read_or_throw( const std::wstring& s, wValue& value )
50+
{
51+
read_string_or_throw( s, value );
52+
}
53+
54+
bool json_spirit::read( std::wistream& is, wValue& value )
55+
{
56+
return read_stream( is, value );
57+
}
58+
59+
void json_spirit::read_or_throw( std::wistream& is, wValue& value )
60+
{
61+
read_stream_or_throw( is, value );
62+
}
63+
64+
bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value )
65+
{
66+
return read_range( begin, end, value );
67+
}
68+
69+
void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wValue& value )
70+
{
71+
begin = read_range_or_throw( begin, end, value );
72+
}
7373
#endif
7474

75-
bool json_spirit::read( const std::string& s, mValue& value )
76-
{
77-
return read_string( s, value );
78-
}
79-
80-
void json_spirit::read_or_throw( const std::string& s, mValue& value )
81-
{
82-
read_string_or_throw( s, value );
83-
}
84-
85-
bool json_spirit::read( std::istream& is, mValue& value )
86-
{
87-
return read_stream( is, value );
88-
}
89-
90-
void json_spirit::read_or_throw( std::istream& is, mValue& value )
91-
{
92-
read_stream_or_throw( is, value );
93-
}
94-
95-
bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value )
96-
{
97-
return read_range( begin, end, value );
98-
}
99-
100-
void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value )
101-
{
102-
begin = read_range_or_throw( begin, end, value );
103-
}
104-
105-
#ifndef BOOST_NO_STD_WSTRING
106-
107-
bool json_spirit::read( const std::wstring& s, wmValue& value )
108-
{
109-
return read_string( s, value );
110-
}
111-
112-
void json_spirit::read_or_throw( const std::wstring& s, wmValue& value )
113-
{
114-
read_string_or_throw( s, value );
115-
}
116-
117-
bool json_spirit::read( std::wistream& is, wmValue& value )
118-
{
119-
return read_stream( is, value );
120-
}
121-
122-
void json_spirit::read_or_throw( std::wistream& is, wmValue& value )
123-
{
124-
read_stream_or_throw( is, value );
125-
}
126-
127-
bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value )
128-
{
129-
return read_range( begin, end, value );
130-
}
131-
132-
void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value )
133-
{
134-
begin = read_range_or_throw( begin, end, value );
135-
}
75+
#ifdef JSON_SPIRIT_MVALUE_ENABLED
76+
bool json_spirit::read( const std::string& s, mValue& value )
77+
{
78+
return read_string( s, value );
79+
}
80+
81+
void json_spirit::read_or_throw( const std::string& s, mValue& value )
82+
{
83+
read_string_or_throw( s, value );
84+
}
85+
86+
bool json_spirit::read( std::istream& is, mValue& value )
87+
{
88+
return read_stream( is, value );
89+
}
90+
91+
void json_spirit::read_or_throw( std::istream& is, mValue& value )
92+
{
93+
read_stream_or_throw( is, value );
94+
}
95+
96+
bool json_spirit::read( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value )
97+
{
98+
return read_range( begin, end, value );
99+
}
100+
101+
void json_spirit::read_or_throw( std::string::const_iterator& begin, std::string::const_iterator end, mValue& value )
102+
{
103+
begin = read_range_or_throw( begin, end, value );
104+
}
105+
#endif
136106

107+
#if defined( JSON_SPIRIT_WMVALUE_ENABLED ) && !defined( BOOST_NO_STD_WSTRING )
108+
bool json_spirit::read( const std::wstring& s, wmValue& value )
109+
{
110+
return read_string( s, value );
111+
}
112+
113+
void json_spirit::read_or_throw( const std::wstring& s, wmValue& value )
114+
{
115+
read_string_or_throw( s, value );
116+
}
117+
118+
bool json_spirit::read( std::wistream& is, wmValue& value )
119+
{
120+
return read_stream( is, value );
121+
}
122+
123+
void json_spirit::read_or_throw( std::wistream& is, wmValue& value )
124+
{
125+
read_stream_or_throw( is, value );
126+
}
127+
128+
bool json_spirit::read( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value )
129+
{
130+
return read_range( begin, end, value );
131+
}
132+
133+
void json_spirit::read_or_throw( std::wstring::const_iterator& begin, std::wstring::const_iterator end, wmValue& value )
134+
{
135+
begin = read_range_or_throw( begin, end, value );
136+
}
137137
#endif

0 commit comments

Comments
 (0)