Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cinemast committed Mar 29, 2019
2 parents 0201ebb + b938e7a commit 4ed5b00
Show file tree
Hide file tree
Showing 29 changed files with 217 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
profile

# xcode noise
build2/*
build/*
*.mode1
*.mode1v3
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before_install:
then
brew update
brew install jsoncpp argtable curl hiredis redis
brew install libmicrohttpd --with-ssl
brew install libmicrohttpd
fi
matrix:
Expand Down
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v1.1.1] - 2018-10-31
## [v1.2.0] - 2019-03-29
### Added
- The `HttpServer` connector now has a `BindLocalhost` method (#261)

### Fixed
- Don't precompress and honor GnuInstallDir for manpage of jsonrpcstub (#252)
- Arch Linux CI build (base image changed)
- brew CI build (no longer has `--ssl` flag for libmicrohttpd)
- Catching `Jsoncpp::Exception` for `.parse()` invocations
- Compile issue when building static only (#263)
- Update catch2 to 2.7.0 and fix include path (#251)
- Removed deprecated jsoncpp invocations


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

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

## Changed
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ if (${CMAKE_MAJOR_VERSION} GREATER 2)
endif()

set(MAJOR_VERSION 1)
set(MINOR_VERSION 1)
set(PATCH_VERSION 1)
set(MINOR_VERSION 2)
set(PATCH_VERSION 0)
set(SO_VERSION 1)

if(NOT MSVC)
Expand Down
2 changes: 1 addition & 1 deletion cmake/libjsonrpccpp-client.pc.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: libjsonrpccpp-client
Description: A C++ client implementation of json-rpc.
Version: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-client -lcurl -lhiredis
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-client ${CLIENT_LIBS}
Cflags: -I${FULL_PATH_INCLUDEDIR}
2 changes: 1 addition & 1 deletion cmake/libjsonrpccpp-server.pc.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: libjsonrpccpp-server
Description: A C++ server implementation of json-rpc.
Version: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-server -lmicrohttpd -lhiredis
Libs: -L${FULL_PATH_LIBDIR} -ljsoncpp -ljsonrpccpp-common -ljsonrpccpp-server ${SERVER_LIBS}
Cflags: -I${FULL_PATH_INCLUDEDIR}
2 changes: 1 addition & 1 deletion docker/ArchLinux.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM base/archlinux:latest
FROM archlinux/base:latest
MAINTAINER Peter Spiess-Knafl <[email protected]>
ENV OS=arch
RUN pacman -Sy --noconfirm \
Expand Down
4 changes: 2 additions & 2 deletions src/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ include(ExternalProject)
ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
URL https://github.com/catchorg/Catch2/archive/v2.0.1.tar.gz
URL_HASH SHA1=5c191a031edebd0525640ed2f38cbf64bacb1803
URL https://github.com/catchorg/Catch2/archive/v2.7.0.tar.gz
URL_HASH SHA1=6df37d5b64a71b840a6a9d8c79c3705aa8a3f56e
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
Expand Down
10 changes: 8 additions & 2 deletions src/jsonrpccpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,22 @@ set(client_connector_libs "")
set(server_connector_source "")
set(server_connector_header "")
set(server_connector_libs "")
set(SERVER_LIBS "")
set(CLIENT_LIBS "")

# setup sources for http connectors
if (HTTP_CLIENT)
list(APPEND client_connector_header "client/connectors/httpclient.h")
list(APPEND client_connector_source "client/connectors/httpclient.cpp")
list(APPEND client_connector_libs ${CURL_LIBRARIES})
list(APPEND client_connector_libs ${CURL_LIBRARIES})
set(CLIENT_LIBS "${CLIENT_LIBS} -lcurl")
endif()

if (HTTP_SERVER)
list(APPEND server_connector_header "server/connectors/httpserver.h")
list(APPEND server_connector_source "server/connectors/httpserver.cpp")
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${MHD_LIBRARIES})
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${MHD_LIBRARIES})
set(SERVER_LIBS "${SERVER_LIBS} -lmicrohttpd")
endif()

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

if (REDIS_SERVER)
list(APPEND server_connector_header "server/connectors/redisserver.h")
list(APPEND server_connector_source "server/connectors/redisserver.cpp")
list(APPEND server_connector_libs ${CMAKE_THREAD_LIBS_INIT} ${HIREDIS_LIBRARIES})
set(SERVER_LIBS "${SERVER_LIBS} -lhiredis")
endif()

# setup sources for unix domain socket connectors
Expand Down
9 changes: 5 additions & 4 deletions src/jsonrpccpp/client/batchcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ int BatchCall::addCall(const string &methodname, const Json::Value &params,
string BatchCall::toString(bool fast) const {
string result;
if (fast) {
Json::FastWriter writer;
result = writer.write(this->result);
Json::StreamWriterBuilder wbuilder;
wbuilder["indentation"] = "";
result = Json::writeString(wbuilder,this->result);
} else {
Json::StyledWriter writer;
result = writer.write(this->result);
Json::StreamWriterBuilder wbuilder;
result = Json::writeString(wbuilder, this->result);
}
return result;
}
10 changes: 7 additions & 3 deletions src/jsonrpccpp/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ void Client::CallProcedures(const BatchCall &calls, BatchResponse &result) {
Json::Reader reader;
Json::Value tmpresult;

if (!reader.parse(response, tmpresult) || !tmpresult.isArray()) {
throw JsonRpcException(Errors::ERROR_CLIENT_INVALID_RESPONSE,
"Array expected.");
try {
if (!reader.parse(response, tmpresult) || !tmpresult.isArray()) {
throw JsonRpcException(Errors::ERROR_CLIENT_INVALID_RESPONSE, "Array expected.");
}
} catch (const Json::Exception& e) {
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), response);
}


for (unsigned int i = 0; i < tmpresult.size(); i++) {
if (tmpresult[i].isObject()) {
Expand Down
20 changes: 12 additions & 8 deletions src/jsonrpccpp/client/rpcprotocolclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ void RpcProtocolClient::BuildRequest(const std::string &method,
const Json::Value &parameter,
std::string &result, bool isNotification) {
Json::Value request;
Json::FastWriter writer;
Json::StreamWriterBuilder wbuilder;
wbuilder["indentation"] = "";
this->BuildRequest(1, method, parameter, request, isNotification);
if (omitEndingLineFeed) {
writer.omitEndingLineFeed();
}
result = writer.write(request);

result = Json::writeString(wbuilder, request);
}

void RpcProtocolClient::HandleResponse(const std::string &response,
Json::Value &result) {
Json::Reader reader;
Json::Value value;
if (reader.parse(response, value)) {
this->HandleResponse(value, result);
} else {

try {
if (reader.parse(response, value)) {
this->HandleResponse(value, result);
} else {
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " " + response);
}
} catch (Json::Exception& e) {
throw JsonRpcException(Errors::ERROR_RPC_JSON_PARSE_ERROR, " " + response);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/jsonrpccpp/common/specificationwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ SpecificationWriter::toJsonValue(const vector<Procedure> &procedures) {
return result;
}
std::string SpecificationWriter::toString(const vector<Procedure> &procedures) {
Json::StyledWriter wr;
return wr.write(toJsonValue(procedures));
Json::StreamWriterBuilder wb;
wb["indentation"] = " ";
return Json::writeString(wb, toJsonValue(procedures));
}
bool SpecificationWriter::toFile(const std::string &filename,
const vector<Procedure> &procedures) {
Expand Down
17 changes: 12 additions & 5 deletions src/jsonrpccpp/server/abstractprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,25 @@ void AbstractProtocolHandler::HandleRequest(const std::string &request,
Json::Reader reader;
Json::Value req;
Json::Value resp;
Json::FastWriter w;
Json::StreamWriterBuilder wbuilder;
wbuilder["indentation"] = "";

if (reader.parse(request, req, false)) {
this->HandleJsonRequest(req, resp);
} else {
try {
if (reader.parse(request, req, false)) {
this->HandleJsonRequest(req, resp);
} else {
this->WrapError(
Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR,
Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR), resp);
}
} catch (const Json::Exception &e) {
this->WrapError(Json::nullValue, Errors::ERROR_RPC_JSON_PARSE_ERROR,
Errors::GetErrorMessage(Errors::ERROR_RPC_JSON_PARSE_ERROR),
resp);
}

if (resp != Json::nullValue)
retValue = w.write(resp);
retValue = Json::writeString(wbuilder,resp);
}

void AbstractProtocolHandler::ProcessRequest(const Json::Value &request,
Expand Down
24 changes: 22 additions & 2 deletions src/jsonrpccpp/server/connectors/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "httpserver.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <jsonrpccpp/common/specificationparser.h>
#include <sstream>
Expand All @@ -29,7 +30,9 @@ struct mhd_coninfo {
HttpServer::HttpServer(int port, const std::string &sslcert,
const std::string &sslkey, int threads)
: AbstractServerConnector(), port(port), threads(threads), running(false),
path_sslcert(sslcert), path_sslkey(sslkey), daemon(NULL) {}
path_sslcert(sslcert), path_sslkey(sslkey), daemon(NULL), bindlocalhost(false) {}

HttpServer::~HttpServer() {}

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

HttpServer& HttpServer::BindLocalhost() {
this->bindlocalhost = true;
return *this;
}

bool HttpServer::StartListening() {
if (!this->running) {
const bool has_epoll =
(MHD_is_feature_supported(MHD_FEATURE_EPOLL) == MHD_YES);
const bool has_poll =
(MHD_is_feature_supported(MHD_FEATURE_POLL) == MHD_YES);
unsigned int mhd_flags;

if (has_epoll)
// In MHD version 0.9.44 the flag is renamed to
// MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY. In later versions both
Expand All @@ -59,7 +68,18 @@ bool HttpServer::StartListening() {
#endif
else if (has_poll)
mhd_flags = MHD_USE_POLL_INTERNALLY;
if (this->path_sslcert != "" && this->path_sslkey != "") {

if (this->bindlocalhost) {
memset(&this->loopback_addr, 0, sizeof(this->loopback_addr));
loopback_addr.sin_family = AF_INET;
loopback_addr.sin_port = htons(this->port);
loopback_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

this->daemon = MHD_start_daemon(
mhd_flags, this->port, NULL, NULL, HttpServer::callback, this,
MHD_OPTION_THREAD_POOL_SIZE, this->threads, MHD_OPTION_SOCK_ADDR, (struct sockaddr *)(&(this->loopback_addr)), MHD_OPTION_END);

} else if (this->path_sslcert != "" && this->path_sslkey != "") {
try {
SpecificationParser::GetFileContent(this->path_sslcert, this->sslcert);
SpecificationParser::GetFileContent(this->path_sslkey, this->sslkey);
Expand Down
Loading

0 comments on commit 4ed5b00

Please sign in to comment.