Skip to content

Commit 2bc6afb

Browse files
committed
Merge pull request #541 from celsius/0.11-devel-fix-disable-ssl
Fix for issue #444 "Unable to compile without OpenSSL"
2 parents 24f3a44 + 3532402 commit 2bc6afb

File tree

6 files changed

+63
-19
lines changed

6 files changed

+63
-19
lines changed

.travis.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ compiler:
66
- clang
77

88
env:
9-
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release"
10-
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release"
11-
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug"
12-
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug"
13-
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release"
14-
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release"
15-
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug"
16-
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug"
9+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
10+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
11+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
12+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
13+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
14+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="ON"
15+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
16+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="ON"
17+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
18+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
19+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
20+
- BOOST_VER=1.54.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
21+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
22+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Release" ENABLE_HTTPS="OFF"
23+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="ON" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
24+
- BOOST_VER=1.55.0 BUILD_SHARED_LIBS="OFF" CMAKE_BUILD_TYPE="Debug" ENABLE_HTTPS="OFF"
1725

1826
before_install:
1927
- if [ "${CXX}" == "g++" ] || [ ${BUILD_SHARED_LIBS} = "OFF" ]; then
@@ -39,6 +47,7 @@ install:
3947
script:
4048
- cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
4149
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
50+
-DCPP-NETLIB_ENABLE_HTTPS=${ENABLE_HTTPS}
4251
- make
4352
- make test
4453

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option( CPP-NETLIB_BUILD_SHARED_LIBS "Build cpp-netlib as shared libraries." OFF
1010
option( CPP-NETLIB_BUILD_TESTS "Build the cpp-netlib project tests." ON)
1111
option( CPP-NETLIB_BUILD_EXPERIMENTS "Build the cpp-netlib project experiments." ON)
1212
option( CPP-NETLIB_BUILD_EXAMPLES "Build the cpp-netlib project examples." ON)
13+
option( CPP-NETLIB_ENABLE_HTTPS "Build cpp-netlib with support for https if OpenSSL is found." ON)
1314

1415
include(GNUInstallDirs)
1516

@@ -43,7 +44,11 @@ set(Boost_USE_MULTI_THREADED ON)
4344
find_package( Boost 1.54.0
4445
REQUIRED unit_test_framework system regex date_time thread filesystem
4546
program_options chrono atomic )
46-
find_package( OpenSSL )
47+
48+
if (CPP-NETLIB_ENABLE_HTTPS)
49+
find_package( OpenSSL )
50+
endif()
51+
4752
find_package( Threads )
4853
set(CMAKE_VERBOSE_MAKEFILE true)
4954

boost/network/protocol/http/server/async_connection.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,18 @@ struct async_connection
174174
public:
175175
async_connection(asio::io_service& io_service, Handler& handler,
176176
utils::thread_pool& thread_pool,
177-
boost::shared_ptr<boost::asio::ssl::context> ctx =
178-
boost::shared_ptr<boost::asio::ssl::context>())
177+
boost::shared_ptr<ssl_context> ctx =
178+
boost::shared_ptr<ssl_context>())
179179
: strand(io_service),
180180
handler(handler),
181181
thread_pool_(thread_pool),
182182
headers_buffer(
183183
BOOST_NETWORK_HTTP_SERVER_CONNECTION_HEADER_BUFFER_MAX_SIZE),
184+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
184185
socket_(io_service, ctx),
186+
#else
187+
socket_(io_service),
188+
#endif
185189
handshake_done(false),
186190
headers_already_sent(false),
187191
headers_in_progress(false) {
@@ -379,21 +383,25 @@ struct async_connection
379383
}
380384

381385
void read_more(state_t state) {
386+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
382387
if (socket_.is_ssl_enabled() && !handshake_done) {
383388
socket_.async_handshake(
384389
boost::asio::ssl::stream_base::server,
385390
boost::bind(&async_connection::handle_handshake,
386391
async_connection<Tag, Handler>::shared_from_this(),
387392
boost::asio::placeholders::error, state));
388393
} else {
394+
#endif
389395
socket_.async_read_some(
390396
asio::buffer(read_buffer_),
391397
strand.wrap(
392398
boost::bind(&async_connection<Tag, Handler>::handle_read_data,
393399
async_connection<Tag, Handler>::shared_from_this(),
394400
state, boost::asio::placeholders::error,
395401
boost::asio::placeholders::bytes_transferred)));
402+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
396403
}
404+
#endif
397405
}
398406

399407
void handle_read_data(state_t state, boost::system::error_code const& ec,

boost/network/protocol/http/server/async_server.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct async_server_base : server_storage_base, socket_options_base {
8989
boost::mutex listening_mutex_;
9090
boost::mutex stopping_mutex_;
9191
bool listening;
92-
boost::shared_ptr<boost::asio::ssl::context> ctx_;
92+
boost::shared_ptr<ssl_context> ctx_;
9393

9494
void handle_stop() {
9595
scoped_mutex_lock stopping_lock(stopping_mutex_);
@@ -111,12 +111,20 @@ struct async_server_base : server_storage_base, socket_options_base {
111111
BOOST_NETWORK_MESSAGE("Error accepting connection, reason: " << ec);
112112
}
113113

114+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
114115
socket_options_base::socket_options(new_connection->socket().next_layer());
116+
#else
117+
socket_options_base::socket_options(new_connection->socket());
118+
#endif
115119

116120
new_connection->start();
117121
new_connection.reset(new connection(service_, handler, *thread_pool, ctx_));
118122
acceptor.async_accept(
123+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
119124
new_connection->socket().next_layer(),
125+
#else
126+
new_connection->socket(),
127+
#endif
120128
boost::bind(&async_server_base<Tag, Handler>::handle_accept, this,
121129
boost::asio::placeholders::error));
122130
}
@@ -155,7 +163,11 @@ struct async_server_base : server_storage_base, socket_options_base {
155163
}
156164
new_connection.reset(new connection(service_, handler, *thread_pool, ctx_));
157165
acceptor.async_accept(
166+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
158167
new_connection->socket().next_layer(),
168+
#else
169+
new_connection->socket(),
170+
#endif
159171
boost::bind(&async_server_base<Tag, Handler>::handle_accept, this,
160172
boost::asio::placeholders::error));
161173
listening = true;

boost/network/protocol/http/server/options.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <boost/asio/io_service.hpp>
1212
#include <boost/asio/socket_base.hpp>
13-
#include <boost/asio/ssl.hpp>
13+
#include <boost/network/protocol/stream_handler.hpp>
1414
#include <boost/network/traits/string.hpp>
1515
#include <boost/network/utils/thread_pool.hpp>
1616
#include <boost/optional.hpp>
@@ -81,7 +81,7 @@ struct server_options {
8181
swap(context_, other.context_);
8282
}
8383

84-
server_options &context(boost::shared_ptr<boost::asio::ssl::context> v) {
84+
server_options &context(boost::shared_ptr<ssl_context> v) {
8585
context_ = v;
8686
return *this;
8787
}
@@ -172,7 +172,7 @@ struct server_options {
172172
boost::shared_ptr<utils::thread_pool> thread_pool() const {
173173
return thread_pool_;
174174
}
175-
boost::shared_ptr<boost::asio::ssl::context> context() const {
175+
boost::shared_ptr<ssl_context> context() const {
176176
return context_;
177177
}
178178

@@ -194,7 +194,7 @@ struct server_options {
194194
boost::optional<boost::asio::socket_base::send_low_watermark>
195195
send_low_watermark_;
196196
boost::shared_ptr<utils::thread_pool> thread_pool_;
197-
boost::shared_ptr<boost::asio::ssl::context> context_;
197+
boost::shared_ptr<ssl_context> context_;
198198
};
199199

200200
template <class Tag, class Handler>

boost/network/protocol/stream_handler.hpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include <boost/asio/detail/throw_error.hpp>
1515
#include <boost/asio/error.hpp>
1616
#include <boost/asio.hpp>
17+
#ifdef BOOST_NETWORK_ENABLE_HTTPS
1718
#include <boost/asio/ssl.hpp>
19+
#endif
1820
#include <boost/asio/detail/push_options.hpp>
1921
#include <boost/asio/detail/config.hpp>
2022
#include <boost/asio/detail/handler_type_requirements.hpp>
@@ -28,9 +30,16 @@
2830
namespace boost {
2931
namespace network {
3032

31-
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
3233
typedef boost::asio::ip::tcp::socket tcp_socket;
3334

35+
#ifndef BOOST_NETWORK_ENABLE_HTTPS
36+
typedef tcp_socket stream_handler;
37+
typedef void ssl_context;
38+
#else
39+
40+
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
41+
typedef boost::asio::ssl::context ssl_context;
42+
3443
struct stream_handler {
3544
public:
3645
stream_handler(boost::shared_ptr<tcp_socket> socket)
@@ -42,8 +51,8 @@ struct stream_handler {
4251
: ssl_sock_(socket), ssl_enabled(true) {}
4352

4453
stream_handler(boost::asio::io_service& io,
45-
boost::shared_ptr<boost::asio::ssl::context> ctx =
46-
boost::shared_ptr<boost::asio::ssl::context>()) {
54+
boost::shared_ptr<ssl_context> ctx =
55+
boost::shared_ptr<ssl_context>()) {
4756
tcp_sock_ = boost::make_shared<tcp_socket>(boost::ref(io));
4857
ssl_enabled = false;
4958
if (ctx) {
@@ -172,6 +181,7 @@ struct stream_handler {
172181
boost::shared_ptr<ssl_socket> ssl_sock_;
173182
bool ssl_enabled;
174183
};
184+
#endif
175185
}
176186
}
177187

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy