Skip to content

Commit 08b5852

Browse files
committed
Modified some code to get as much working on MSVC 10 as possible. There is still a compiler error in protocol/http/algorithms/linearize.hpp.
1 parent 98a44c8 commit 08b5852

File tree

4 files changed

+52
-32
lines changed

4 files changed

+52
-32
lines changed

CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ if (Boost_FOUND)
1111
set(Boost_USE_STATIC_LIBS ON)
1212
set(Boost_USE_MULTI_THREADED ON)
1313
include_directories(${Boost_INCLUDE_DIRS})
14-
endif()
14+
endif(Boost_FOUND)
15+
if (MSVC)
16+
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
17+
endif(MSVC)
18+
if (WIN32)
19+
add_definitions(-D_WIN32_WINNT=0x0501)
20+
endif(WIN32)
1521
enable_testing()
1622
add_subdirectory(libs/network/build)
1723
add_subdirectory(libs/network/test)
18-
add_subdirectory(libs/mime/test)
24+
if (NOT MSVC)
25+
add_subdirectory(libs/mime/test)
26+
endif(NOT_MSVC)
1927
add_subdirectory(libs/network/example)
2028

boost/network/protocol/http/policies/simple_connection.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace boost { namespace network { namespace http {
2929
typedef function<typename resolver_base::resolver_iterator_pair(resolver_type &, string_type const &, string_type const &)> resolver_function_type;
3030

3131
struct connection_impl {
32-
connection_impl(resolver_type & resolver, bool follow_redirect, string_type const & hostname, string_type const & port, resolver_function_type resolve, bool https, optional<string_type> const & certificate_filename = optional<string_type>(), optional<string_type> const & verify_path = optional<string_type>())
32+
connection_impl(resolver_type & resolver, bool follow_redirect, string_type const & hostname, string_type const & port, resolver_function_type resolve, bool https, optional<string_type> const & certificate_filename = optional<string_type>(), optional<string_type> const & verify_path = optional<string_type>())
3333
: pimpl()
34-
, follow_redirect_(follow_redirect)
34+
, follow_redirect_(follow_redirect)
3535
{
3636
pimpl.reset(impl::sync_connection_base<Tag,version_major,version_minor>::new_connection(resolver, resolve, https, certificate_filename, verify_path));
3737
}
@@ -54,7 +54,7 @@ namespace boost { namespace network { namespace http {
5454
boost::uint16_t status = response_.status();
5555
if (status >= 300 && status <= 307) {
5656
typename headers_range<http::basic_response<Tag> >::type location_range = headers(response_)["Location"];
57-
typename range_iterator<typename headers_range<http::basic_request<Tag> >::type>::type location_header = boost::begin(location_range);
57+
typename range_iterator<typename headers_range<http::basic_response<Tag> >::type>::type location_header = boost::begin(location_range);
5858
if (location_header != boost::end(location_range)) {
5959
request_.uri(location_header->second);
6060
} else throw std::runtime_error("Location header not defined in redirect response.");
@@ -97,7 +97,7 @@ namespace boost { namespace network { namespace http {
9797

9898
void cleanup() { }
9999

100-
simple_connection_policy(bool cache_resolved, bool follow_redirect)
100+
simple_connection_policy(bool cache_resolved, bool follow_redirect)
101101
: resolver_base(cache_resolved), follow_redirect_(follow_redirect) {}
102102

103103
// member variables

libs/network/example/CMakeLists.txt

+26-14
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,40 @@
66
include_directories(${CPP-NETLIB_SOURCE_DIR})
77
find_package( Boost 1.41.0 COMPONENTS program_options system regex date_time thread filesystem )
88
find_package( OpenSSL )
9-
include_directories(${OPENSSL_INCLUDE_DIR})
109
find_package( Threads )
11-
set(Boost_USE_STATIC_LIBS ON)
12-
set(Boost_USE_MULTITHREADED ON)
10+
11+
if (Boost_FOUND)
12+
set(Boost_USE_STATIC_LIBS ON)
13+
set(Boost_USE_MULTITHREADED ON)
14+
endif (Boost_FOUND)
15+
16+
if (OPENSSL_FOUND)
17+
include_directories(${OPENSSL_INCLUDE_DIR})
18+
endif (OPENSSL_FOUND)
1319

1420
if (Boost_FOUND)
1521
add_executable(http_client http_client.cpp)
22+
add_dependencies(http_client cppnetlib-uri-parsers)
23+
target_link_libraries(http_client ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
24+
set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
25+
1626
add_executable(simple_wget simple_wget.cpp)
27+
add_dependencies(simple_wget cppnetlib-uri-parsers)
28+
target_link_libraries(simple_wget ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
29+
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
30+
1731
add_executable(hello_world_server http/hello_world_server.cpp)
18-
add_executable(fileserver http/fileserver.cpp)
32+
target_link_libraries(hello_world_server ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
33+
set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
34+
35+
if (UNIX)
36+
add_executable(fileserver http/fileserver.cpp)
37+
target_link_libraries(fileserver ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
38+
set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
39+
endif (UNIX)
40+
1941
add_executable(uri uri.cpp)
20-
add_dependencies(http_client cppnetlib-uri-parsers)
21-
add_dependencies(simple_wget cppnetlib-uri-parsers)
2242
add_dependencies(uri cppnetlib-uri-parsers)
23-
target_link_libraries(http_client ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} cppnetlib-uri-parsers)
24-
target_link_libraries(simple_wget ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} cppnetlib-uri-parsers)
25-
target_link_libraries(hello_world_server ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} )
26-
target_link_libraries(fileserver ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
2743
target_link_libraries(uri cppnetlib-uri-parsers)
28-
set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
29-
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
30-
set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
31-
set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
3244
set_target_properties(uri PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
3345
endif()

libs/network/test/http/http_test_server.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright Kim Grasman 2008.
33
// Distributed under the Boost Software License, Version 1.0.
44
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -16,14 +16,14 @@
1616
#include <windows.h>
1717

1818
// ShellExecuteEx
19-
#include <shellapi.h>
19+
#include <shellapi.h>
2020
#pragma comment( lib, "shell32" )
2121
#else
2222
#include <unistd.h> // fork, execlp etc.
2323
#include <sys/types.h>
2424
#include <sys/wait.h> // for waitpid
2525
#include <sys/stat.h> // for chmod
26-
#include <signal.h> // for kill
26+
#include <signal.h> // for kill
2727
#endif
2828

2929
struct http_test_server
@@ -61,7 +61,7 @@ struct http_test_server
6161
boost::filesystem::path get_server_path(const boost::filesystem::path& base_path) {
6262
using namespace boost::filesystem;
6363

64-
const path script_name =
64+
const path script_name =
6565
#if defined(HTTPS_SERVER_TEST)
6666
"https_test_server.py"
6767
#else
@@ -84,17 +84,17 @@ struct http_test_server
8484
script_handle_t launch_python_script(const boost::filesystem::path& python_script_path) {
8585
using namespace boost::filesystem;
8686

87-
path::string_type script_name = python_script_path.filename().string();
88-
path::string_type script_dir = python_script_path.parent_path().string();
87+
path::string_type script_name = python_script_path.filename().native();
88+
path::string_type script_dir = python_script_path.parent_path().native();
8989

9090
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
9191
SHELLEXECUTEINFOA sei = {0};
9292
sei.cbSize = sizeof(sei);
9393
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
9494
sei.lpVerb = "open";
9595
sei.lpFile = "python.exe";
96-
sei.lpParameters = script_name.c_str();
97-
sei.lpDirectory = script_dir.c_str();
96+
sei.lpParameters = reinterpret_cast<LPCSTR>(script_name.c_str());
97+
sei.lpDirectory = reinterpret_cast<LPCSTR>(script_dir.c_str());
9898
sei.nShow = SW_SHOWNOACTIVATE;
9999

100100
if (!ShellExecuteExA(&sei))
@@ -107,16 +107,16 @@ struct http_test_server
107107
if (child_process < 0)
108108
return false;
109109

110-
if (child_process == 0) {
110+
if (child_process == 0) {
111111
// child process
112-
112+
113113
// cd into script dir and launch python script
114114
current_path(script_dir);
115115

116116
if (execlp("python", "python", script_name.c_str(), (char*)NULL) == -1)
117117
return 0;
118-
}
119-
else {
118+
}
119+
else {
120120
// parent
121121
sleep(1);
122122
}

0 commit comments

Comments
 (0)