Skip to content

Commit ba8c573

Browse files
committed
Merge pull request #48 from deanberris/0.9-devel
0.9 devel
2 parents 849312d + e1911e0 commit ba8c573

File tree

7 files changed

+133
-138
lines changed

7 files changed

+133
-138
lines changed

CMakeLists.txt

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,36 @@
55

66
cmake_minimum_required(VERSION 2.6)
77
project(CPP-NETLIB)
8-
find_package( Boost 1.41.0 )
8+
set(Boost_USE_STATIC_LIBS ON)
9+
set(Boost_USE_MULTI_THREADED ON)
10+
find_package( Boost 1.45.0 REQUIRED unit_test_framework system regex date_time thread filesystem program_options )
911
find_package( OpenSSL )
1012
find_package( Threads )
1113
set(CMAKE_VERBOSE_MAKEFILE true)
1214

1315
if (CMAKE_BUILD_TYPE MATCHES Debug)
1416
add_definitions(-DBOOST_NETWORK_DEBUG)
1517
endif()
16-
if (Boost_FOUND)
17-
set(Boost_USE_STATIC_LIBS ON)
18-
set(Boost_USE_MULTI_THREADED ON)
19-
include_directories(${Boost_INCLUDE_DIRS})
20-
endif(Boost_FOUND)
21-
if (MSVC)
22-
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
23-
endif(MSVC)
24-
if (WIN32)
25-
add_definitions(-D_WIN32_WINNT=0x0501)
26-
endif(WIN32)
27-
enable_testing()
2818

2919
if (OPENSSL_FOUND)
3020
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
3121
endif()
3222

33-
add_subdirectory(libs/network/src)
34-
add_subdirectory(libs/network/test)
35-
if (NOT MSVC)
36-
add_subdirectory(libs/mime/test)
37-
endif(NOT MSVC)
38-
add_subdirectory(libs/network/example)
23+
if (Boost_FOUND)
24+
if (MSVC)
25+
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
26+
endif(MSVC)
27+
if (WIN32)
28+
add_definitions(-D_WIN32_WINNT=0x0501)
29+
endif(WIN32)
30+
include_directories(${Boost_INCLUDE_DIRS})
31+
enable_testing()
32+
add_subdirectory(libs/network/src)
33+
add_subdirectory(libs/network/test)
34+
if (NOT MSVC)
35+
add_subdirectory(libs/mime/test)
36+
endif(NOT MSVC)
37+
add_subdirectory(libs/network/example)
38+
endif(Boost_FOUND)
3939

40+
enable_testing()

libs/network/example/CMakeLists.txt

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,54 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR})
7-
find_package( Boost 1.41.0 COMPONENTS program_options system regex date_time thread filesystem )
8-
find_package( OpenSSL )
9-
find_package( Threads )
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)
19-
20-
if (Boost_FOUND)
21-
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-
26-
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-
31-
add_executable(hello_world_server http/hello_world_server.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-
41-
add_executable(uri uri.cpp)
42-
add_dependencies(uri cppnetlib-uri-parsers)
43-
target_link_libraries(uri cppnetlib-uri-parsers)
44-
set_target_properties(uri PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
45-
46-
add_executable(uri_builder uri_builder.cpp)
47-
add_dependencies(uri_builder cppnetlib-uri-parsers)
48-
target_link_libraries(uri_builder cppnetlib-uri-parsers)
49-
set_target_properties(uri_builder PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
50-
51-
endif()
7+
include_directories(${OPENSSL_INCLUDE_DIR})
8+
9+
add_executable(http_client http_client.cpp)
10+
add_executable(simple_wget simple_wget.cpp)
11+
add_executable(hello_world_server http/hello_world_server.cpp)
12+
add_executable(fileserver http/fileserver.cpp)
13+
add_executable(uri uri.cpp)
14+
add_dependencies(http_client cppnetlib-uri-parsers cppnetlib-client-connections)
15+
add_dependencies(simple_wget cppnetlib-uri-parsers cppnetlib-client-connections)
16+
add_dependencies(uri cppnetlib-uri-parsers)
17+
set(BOOST_CLIENT_LIBS
18+
${Boost_PROGRAM_OPTIONS_LIBRARY}
19+
${Boost_THREAD_LIBRARY}
20+
${Boost_SYSTEM_LIBRARY})
21+
22+
set(BOOST_SERVER_LIBS
23+
${Boost_THREAD_LIBRARY}
24+
${Boost_SYSTEM_LIBRARY}
25+
${Boost_PROGRAM_OPTIONS_LIBRARY})
26+
27+
target_link_libraries(http_client
28+
${BOOST_CLIENT_LIBS}
29+
${CMAKE_THREAD_LIBS_INIT}
30+
${OPENSSL_LIBRARIES}
31+
cppnetlib-uri-parsers
32+
cppnetlib-client-connections)
33+
34+
target_link_libraries(simple_wget
35+
${BOOST_CLIENT_LIBS}
36+
${CMAKE_THREAD_LIBS_INIT}
37+
${OPENSSL_LIBRARIES}
38+
cppnetlib-uri-parsers
39+
cppnetlib-client-connections)
40+
41+
target_link_libraries(hello_world_server
42+
${BOOST_SERVER_LIBS}
43+
${CMAKE_THREAD_LIBS_INIT}
44+
${OPENSSL_LIBRARIES})
45+
46+
target_link_libraries(fileserver
47+
${BOOST_SERVER_LIBS}
48+
${Boost_FILESYSTEM_LIBRARY}
49+
${CMAKE_THREAD_LIBS_INIT}
50+
cppnetlib-server-parsers)
51+
52+
target_link_libraries(uri cppnetlib-uri-parsers)
53+
set_target_properties(http_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
54+
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
55+
set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
56+
set_target_properties(fileserver PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
57+
set_target_properties(uri PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)

libs/network/example/http_client.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,21 @@
1111
*/
1212
#include <boost/program_options.hpp>
1313
#include <boost/network/protocol/http.hpp>
14-
#include <boost/function_output_iterator.hpp>
1514
#include <string>
15+
#include <utility>
1616
#include <iostream>
1717

1818
namespace po = boost::program_options;
19-
using namespace std;
20-
21-
struct header_printer {
22-
std::ostream & os;
23-
header_printer(std::ostream & os_) : os(os_) {}
24-
template <class Pair>
25-
void operator()(Pair const & p) {
26-
os << p.first << ": " << p.second << endl;
27-
}
28-
};
2919

3020
int main(int argc, char * argv[]) {
21+
using namespace boost::network;
3122
po::options_description options("Allowed options");
32-
string output_filename, source;
23+
std::string output_filename, source;
3324
bool show_headers;
3425
options.add_options()
3526
("help,h", "produce help message")
3627
("headers,H", "print headers")
37-
("source,s", po::value<string>(&source), "source URL")
28+
("source,s", po::value<std::string>(&source), "source URL")
3829
;
3930

4031
po::positional_options_description positional_options;
@@ -44,47 +35,47 @@ int main(int argc, char * argv[]) {
4435
po::store(po::command_line_parser(argc, argv).options(options).positional(positional_options).run(),
4536
vm);
4637
po::notify(vm);
47-
} catch(exception & e) {
48-
cout << "Error: " << e.what() << endl;
49-
cout << options << endl;
38+
} catch(std::exception & e) {
39+
std::cout << "Error: " << e.what() << std::endl;
40+
std::cout << options << std::endl;
5041
return EXIT_FAILURE;
5142
};
5243

5344
if (vm.count("help")) {
54-
cout << options << endl;
45+
std::cout << options << std::endl;
5546
return EXIT_SUCCESS;
5647
};
5748

5849
if (vm.count("source") < 1) {
59-
cout << "Error: Source URL required." << endl;
60-
cout << options << endl;
50+
std::cout << "Error: Source URL required." << std::endl;
51+
std::cout << options << std::endl;
6152
return EXIT_FAILURE;
6253
};
6354

6455
show_headers = vm.count("headers") ? true : false ;
6556

66-
using namespace boost::network;
6757

6858
typedef http::basic_client<http::tags::http_async_8bit_tcp_resolve, 1, 0>
6959
http_client;
70-
60+
7161
http_client::request request(source);
7262
http_client::string_type destination_ = host(request);
73-
63+
7464
request << ::boost::network::header("Connection", "close");
7565
http_client client(http::_follow_redirects=true);
7666
http_client::response response = client.get(request);
7767

7868
if (show_headers) {
7969
headers_range<http_client::response>::type headers_ = response.headers();
80-
std::copy(headers_.begin(), headers_.end(),
81-
boost::make_function_output_iterator(header_printer(cout)));
82-
cout << endl;
70+
typedef std::pair<std::string, std::string> header_type;
71+
BOOST_FOREACH(header_type const & header, headers_) {
72+
std::cout << header.first << ": " << header.second << std::endl;
73+
}
74+
std::cout << std::endl;
8375
};
84-
76+
8577
body_range<http_client::response>::type body_ = body(response).range();
86-
boost::copy(body_, std::ostream_iterator<char_<http_client::request::tag>::type>(cout));
87-
78+
boost::copy(body_, std::ostream_iterator<char_<http_client::request::tag>::type>(std::cout));
8879
return EXIT_SUCCESS;
8980
}
9081
//]

libs/network/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
include_directories(${CPP-NETLIB_SOURCE_DIR})
10+
1011
set(CPP-NETLIB_URI_SRCS uri/parse.cpp)
1112
add_library(cppnetlib-uri-parsers ${CPP-NETLIB_URI_SRCS})
1213

libs/network/test/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
# http://www.boost.org/LICENSE_1_0.txt)
55

66
include_directories(${CPP-NETLIB_SOURCE_DIR})
7-
find_package( Boost 1.41.0 COMPONENTS unit_test_framework system regex date_time thread filesystem )
8-
set(Boost_USE_STATIC_LIBS ON)
9-
set(Boost_USE_MULTITHREADED ON)
107

118
add_subdirectory(uri)
129
add_subdirectory(http)
@@ -22,17 +19,17 @@ if (Boost_FOUND)
2219
set_source_files_properties(${test}.cpp
2320
PROPERTIES COMPILE_FLAGS "-Wall")
2421
add_executable(cpp-netlib-${test} ${test}.cpp)
25-
add_dependencies(cpp-netlib-${test} cppnetlib-uri-parsers)
22+
add_dependencies(cpp-netlib-${test} cppnetlib-uri-parsers)
2623

27-
# add_dependencies(cpp-netlib-${test} cppnetlib-uri-parsers)
28-
# target_link_libraries(cpp-netlib-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
29-
target_link_libraries(cpp-netlib-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
24+
target_link_libraries(cpp-netlib-${test}
25+
${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers)
3026
if (OPENSSL_FOUND)
3127
target_link_libraries(cpp-netlib-${test} ${OPENSSL_LIBRARIES})
3228
endif()
3329
set_target_properties(cpp-netlib-${test}
3430
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
35-
add_test(cpp-netlib-${test} ${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
31+
add_test(cpp-netlib-${test}
32+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
3633
endforeach (test)
3734

3835
endif()

libs/network/test/http/CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
# http://www.boost.org/LICENSE_1_0.txt)
66

77
include_directories(${CPP-NETLIB_SOURCE_DIR})
8-
find_package( Boost 1.43.0 REQUIRED unit_test_framework system regex thread filesystem )
9-
find_package( OpenSSL )
108

119
if (OPENSSL_FOUND)
1210
include_directories( ${OPENSSL_INCLUDE_DIR} )
1311
add_definitions(-DBOOST_NETWORK_ENABLE_HTTPS)
1412
endif()
1513

16-
find_package( Threads )
17-
set(Boost_USE_STATIC_LIBS ON)
18-
set(Boost_USE_MULTITHREADED ON)
19-
2014
if (Boost_FOUND)
15+
set ( BOOST_LIBS
16+
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
17+
${Boost_THREAD_LIBRARY}
18+
${Boost_SYSTEM_LIBRARY})
2119
set ( TESTS
2220
client_constructor_test
2321
client_get_test
@@ -31,8 +29,13 @@ if (Boost_FOUND)
3129
PROPERTIES COMPILE_FLAGS "-Wall")
3230
endif()
3331
add_executable(cpp-netlib-http-${test} ${test}.cpp)
34-
add_dependencies(cpp-netlib-http-${test} cppnetlib-uri-parsers)
35-
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-uri-parsers cppnetlib-client-connections)
32+
add_dependencies(cpp-netlib-http-${test}
33+
cppnetlib-uri-parsers
34+
cppnetlib-client-connections)
35+
target_link_libraries(cpp-netlib-http-${test}
36+
${BOOST_LIBS} ${CMAKE_THREAD_LIBS_INIT}
37+
cppnetlib-uri-parsers
38+
cppnetlib-client-connections)
3639
if (OPENSSL_FOUND)
3740
target_link_libraries(cpp-netlib-http-${test} ${OPENSSL_LIBRARIES})
3841
endif()
@@ -53,7 +56,7 @@ if (Boost_FOUND)
5356
endif()
5457
add_executable(cpp-netlib-http-${test} ${test}.cpp)
5558
add_dependencies(cpp-netlib-http-${test} cppnetlib-server-parsers)
56-
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
59+
target_link_libraries(cpp-netlib-http-${test} ${BOOST_LIBS} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
5760
set_target_properties(cpp-netlib-http-${test}
5861
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/tests)
5962
add_test(cpp-netlib-http-${test}
@@ -73,7 +76,7 @@ if (Boost_FOUND)
7376
endif()
7477
add_executable(cpp-netlib-http-${test} ${test}.cpp)
7578
add_dependencies(cpp-netlib-http-${test} cppnetlib-server-parsers)
76-
target_link_libraries(cpp-netlib-http-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
79+
target_link_libraries(cpp-netlib-http-${test} ${BOOST_LIBS} ${CMAKE_THREAD_LIBS_INIT} cppnetlib-server-parsers)
7780
set_target_properties(cpp-netlib-http-${test}
7881
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
7982
${CPP-NETLIB_BINARY_DIR}/tests)
@@ -96,7 +99,7 @@ if (Boost_FOUND)
9699
PROPERTIES COMPILE_FLAGS "-Wall")
97100
endif()
98101
add_executable(cpp-netlib-http-inlined-${test} ${test}.cpp)
99-
target_link_libraries(cpp-netlib-http-inlined-${test} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
102+
target_link_libraries(cpp-netlib-http-inlined-${test} ${BOOST_LIBS} ${CMAKE_THREAD_LIBS_INIT})
100103
if (OPENSSL_FOUND)
101104
target_link_libraries(cpp-netlib-http-inlined-${test} ${OPENSSL_LIBRARIES})
102105
endif()

0 commit comments

Comments
 (0)