8000 Merge branch 'develop' · cinemast/libjson-rpc-cpp@4ed5b00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ed5b00

Browse files
committed
Merge branch 'develop'
2 parents 0201ebb + b938e7a commit 4ed5b00

29 files changed

+217
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
profile
44

55
# xcode noise
6+
build2/*
67
build/*
78
*.mode1
89
*.mode1v3

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ before_install:
88
then
99
brew update
1010
brew install jsoncpp argtable curl hiredis redis
11-
brew install libmicrohttpd --with-ssl
11+
brew install libmicrohttpd
1212
fi
1313
1414
matrix:

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [v1.1.1] - 2018-10-31
7+
## [v1.2.0] - 2019-03-29
8+
### Added
9+
- The `HttpServer` connector now has a `BindLocalhost` method (#261)
10+
11+
### Fixed
12+
- Don't precompress and honor GnuInstallDir for manpage of jsonrpcstub (#252)
13+
- Arch Linux CI build (base image changed)
14+
- brew CI build (no longer has `--ssl` flag for libmicrohttpd)
15+
- Catching `Jsoncpp::Exception` for `.parse()` invocations
16+
- Compile issue when building static only (#263)
17+
- Update catch2 to 2.7.0 and fix include path (#251)
18+
- Removed deprecated jsoncpp invocations
19+
820

21+
## [v1.1.1] - 2018-10-31
922
### Fixed
1023
- Build issue on RHEL7 (#244, #246)
1124
- Build with empty install prefix (#226)
@@ -80,7 +93,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8093
- Invalid pointer handling in HTTP-Server
8194

8295
### Added
83-
- HttpServer can now be configured to listen localhost only
8496
- TCP Server + Client connectors
8597

8698
## Changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ if (${CMAKE_MAJOR_VERSION} GREATER 2)
2222
endif()
2323

2424
set(MAJOR_VERSION 1)
25-
set(MINOR_VERSION 1)
26-
set(PATCH_VERSION 1)
25+
set(MINOR_VERSION 2)
26+
set(PATCH_VERSION 0)
2727
set(SO_VERSION 1)
2828

2929
if(NOT MSVC)

cmake/libjsonrpccpp-client.pc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: libjsonrpccpp-client
22
Description: A C++ client implementation of json-rpc.
33
Version: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
4-
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-client -lcurl -lhiredis
4+
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-client ${CLIENT_LIBS}
55
Cflags: -I${FULL_PATH_INCLUDEDIR}

cmake/libjsonrpccpp-server.pc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: libjsonrpccpp-server
22
Description: A C++ server implementation of json-rpc.
33
Version: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
4-
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-server -lmicrohttpd -lhiredis
4+
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-server ${SERVER_LIBS}
55
Cflags: -I${FULL_PATH_INCLUDEDIR}

docker/ArchLinux.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM base/archlinux:latest
1+
FROM archlinux/base:latest
22
MAINTAINER Peter Spiess-Knafl <dev@spiessknafl.at>
33
ENV OS=arch
44
RUN pacman -Sy --noconfirm \

src/catch/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ include(ExternalProject)
55
ExternalProject_Add(
66
catch
77
PREFIX ${CMAKE_BINARY_DIR}/catch
8-
URL https://github.com/catchorg/Catch2/archive/v2.0.1.tar.gz
9-
URL_HASH SHA1=5c191a031edebd0525640ed2f38cbf64bacb1803
8+
URL https://github.com/catchorg/Catch2/archive/v2.7.0.tar.gz
9+
URL_HASH SHA1=6df37d5b64a71b840a6a9d8c79c3705aa8a3f56e
1010
CONFIGURE_COMMAND ""
1111
BUILD_COMMAND ""
1212
INSTALL_COMMAND ""

src/jsonrpccpp/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ set(client_connector_libs "")
3333
set(server_connector_source "")
3434
set(server_connector_header "")
3535
set(server_connector_libs "")
36+
set(SERVER_LIBS "")
37+
set(CLIENT_LIBS "")
3638

3739
# setup sources for http connectors
3840
if (HTTP_CLIENT)
3941
list(APPEND client_connector_header "client/connectors/httpclient.h")
4042
list(APPEND client_connector_source "client/connectors/httpclient.cpp")
41-
list(APPEND client_connector_libs ${CURL_LIBRARIES})
43+
list(APPEND client_connector_libs ${CURL_LIBRARIES})
44+
set(CLIENT_LIBS "${CLIENT_LIBS} -lcurl")
4245
endif()
4346

4447
if (HTTP_SERVER)
4548
list(APPEND server_connector_header "server/connectors/httpserver.h")
4649
list(APPEND server_connector_source "server/connectors/httpserver.cpp")
47-
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${MHD_LIBRARIES})
50+
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${MHD_LIBRARIES})
51+
set(SERVER_LIBS "${SERVER_LIBS} -lmicrohttpd")
4852
endif()
4953

5054
# setup sources for redis connectors
@@ -53,12 +57,14 @@ if (REDIS_CLIENT)
5357
list(APPEND client_connector_source "client/connectors/redisclient.cpp")
5458
list(APPEND client_connector_libs ${HIREDIS_LIBRARIES})
5559
include_directories(${HIREDIS_INCLUDE_DIRS})
60+
set(CLIENT_LIBS "${CLIENT_LIBS} -lhiredis")
5661
endif()
5762

5863
if (REDIS_SERVER)
5964
list(APPEND server_connector_header "server/connectors/redisserver.h")
6065
list(APPEND server_connector_source "server/connectors/redisserver.cpp")
6166
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${HIREDIS_LIBRARIES})
67+
set(SERVER_LIBS "${SERVER_LIBS} -lhiredis")
6268
endif()
6369

6470
# setup sources for unix domain socket connectors

src/jsonrpccpp/client/batchcall.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ int BatchCall::addCall(const string &methodname, const Json::Value &params,
3737
string BatchCall::toString(bool fast) const {
3838
string result;
3939
if (fast) {
40-
Json::FastWriter writer;
41-
result = writer.write(this->result);
40+
Json::StreamWriterBuilder wbuilder;
41+
wbuilder["indentation"] = "";
42+
result = Json::writeString(wbuilder,this->result);
4243
} else {
43-
Json::StyledWriter writer;
44-
result = writer.write(this->result);
44+
Json::StreamWriterBuilder wbuilder;
45+
result = Json::writeString(wbuilder, this->result);
4546
}
4647
return result;
4748
}

src/jsonrpccpp/client/client.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ void Client::CallProcedures(const BatchCall &calls, BatchResponse &result) {
3434
Json::Reader reader;
3535
Json::Value tmpresult;
3636

37-
if (!reader.parse(response, tmpresult) || !tmpresult.isArray()) {
38-
throw JsonRpcException(Errors::ERROR_CLIENT_INVALID_RESPONSE,
39-
"Array expected.");
37+
try {
38+
if (!reader.parse(response, tmpresult) || !tmpresult.isArray()) {
39+
throw JsonRpcException(Errors::ERROR_CLIENT_INVALID_RESPONSE, "Array expected.");
40+
}
41+
} catch (const Json::Exception& e) {
42+
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), response);
4043
}
44+
4145

4246
for (unsigned int i = 0; i < tmpresult.size(); i++) {
4347
if (tmpresult[i].isObject()) {

src/jsonrpccpp/client/rpcprotocolclient.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,25 @@ void RpcProtocolClient::BuildRequest(const std::string &method,
3030
const Json::Value &parameter,
3131
std::string &result, bool isNotification) {
3232
Json::Value request;
33-
Json::FastWriter writer;
33+
Json::StreamWriterBuilder wbuilder;
34+
wbuilder["indentation"] = "";
3435
this->BuildRequest(1, method, parameter, request, isNotification);
35-
if (omitEndingLineFeed) {
36-
writer.omitEndingLineFeed();
37-
}
38-
result = writer.write(request);
36+
37+
result = Json::writeString(wbuilder, request);
3938
}
4039

4140
void RpcProtocolClient::HandleResponse(const std::string &response,
4241
Json::Value &result) {
4342
Json::Reader reader;
4443
Json::Value value;
45-
if (reader.parse(response, value)) {
46-
this->HandleResponse(value, result);
47-
} else {
44+
45+
try {
46+
if (reader.parse(response, value)) {
47+
this->HandleResponse(value, result);
48+
} else {
49+
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " " + response);
50+
}
51+
} catch (Json::Exception& e) {
4852
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " " + response);
4953
}
5054
}

src/jsonrpccpp/common/specificationwriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ SpecificationWriter::toJsonValue(const vector<Procedure> &procedures) {
2828
return result;
2929
}
3030
std::string SpecificationWriter::toString(const vector<Procedure> &procedures) {
31-
Json::StyledWriter wr;
32-
return wr.write(toJsonValue(procedures));
31+
Json::StreamWriterBuilder wb;
32+
wb["indentation"] = " ";
33+
return Json::writeString(wb, toJsonValue(procedures));
3334
}
3435
bool SpecificationWriter::toFile(const std::string &filename,
3536
const vector<Procedure> &procedures) {

src/jsonrpccpp/server/abstractprotocolhandler.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,25 @@ void AbstractProtocolHandler::HandleRequest(const std::string &request,
3131
Json::Reader reader;
3232
Json::Value req;
3333
Json::Value resp;
34-
Json::FastWriter w;
34+
Json::StreamWriterBuilder wbuilder;
35+
wbuilder["indentation"] = "";
3536

36-
if (reader.parse(request, req, false)) {
37-
this->HandleJsonRequest(req, resp);
38-
} else {
37+
try {
38+
if (reader.parse(request, req, false)) {
39+
this->HandleJsonRequest(req, resp);
40+
} else {
41+
this->WrapError(
42+
Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR,
43+
Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
44+
}
45+
} catch (const Json::Exception &e) {
3946
this->WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR,
4047
Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR),
4148
resp);
4249
}
4350

4451
if (resp != Json::nullValue)
45-
retValue = w.write(resp);
52+
retValue = Json::writeString(wbuilder,resp);
4653
}
4754

4855
void AbstractProtocolHandler::ProcessRequest(const Json::Value &request,

src/jsonrpccpp/server/connectors/httpserver.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "httpserver.h"
1111
#include <cstdlib>
12+
#include <cstring>
1213
#include <iostream>
1314
#include <jsonrpccpp/common/specificationparser.h>
1415
#include <sstream>
@@ -29,7 +30,9 @@ struct mhd_coninfo {
2930
HttpServer::HttpServer(int port, const std::string &sslcert,
3031
const std::string &sslkey, int threads)
3132
: AbstractServerConnector(), port(port), threads(threads), running(false),
32-
path_sslcert(sslcert), path_sslkey(sslkey), daemon(NULL) {}
33+
path_sslcert(sslcert), path_sslkey(sslkey), daemon(NULL), bindlocalhost(false) {}
34+
35+
HttpServer::~HttpServer() {}
3336

3437
IClientConnectionHandler *HttpServer::GetHandler(const std::string &url) {
3538
if (AbstractServerConnector::GetHandler() != NULL)
@@ -41,13 +44,19 @@ IClientConnectionHandler *HttpServer::GetHandler(const std::string &url) {
4144
return NULL;
4245
}
4346

47+
HttpServer& HttpServer::BindLocalhost() {
48+
this->bindlocalhost = true;
49+
return *this;
50+
}
51+
4452
bool HttpServer::StartListening() {
4553
if (!this->running) {
4654
const bool has_epoll =
4755
(MHD_is_feature_supported(MHD_FEATURE_EPOLL) == MHD_YES);
4856
const bool has_poll =
4957
(MHD_is_feature_supported(MHD_FEATURE_POLL) == MHD_YES);
5058
unsigned int mhd_flags;
59+
5160
if (has_epoll)
5261
// In MHD version 0.9.44 the flag is renamed to
5362
// MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY. In later versions both
@@ -59,7 +68,18 @@ bool HttpServer::StartListening() {
5968
#endif
6069
else if (has_poll)
6170
mhd_flags = MHD_USE_POLL_INTERNALLY;
62-
if (this->path_sslcert != "" && this->path_sslkey != "") {
71+
72+
if (this->bindlocalhost) {
73+
memset(&this->loopback_addr, 0, sizeof(this->loopback_addr));
74+
loopback_addr.sin_family = AF_INET;
75+
loopback_addr.sin_port = htons(this->port);
76+
loopback_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
77+
78+
this->daemon = MHD_start_daemon(
79+
mhd_flags, this->port, NULL, NULL, HttpServer::callback, this,
80+
MHD_OPTION_THREAD_POOL_SIZE, this->threads, MHD_OPTION_SOCK_ADDR, (struct sockaddr *)(&(this->loopback_addr)), MHD_OPTION_END);
81+
82+
} else if (this->path_sslcert != "" && this->path_sslkey != "") {
6383
try {
6484
SpecificationParser::GetFileContent(this->path_sslcert, this->sslcert);
6585
SpecificationParser::GetFileContent(this->path_sslkey, this->sslkey);

0 commit comments

Comments
 (0)
0