Skip to content

Commit 8a48c83

Browse files
committed
Updated project to use the uri submodule; updated some code in order to handle the new changes.
1 parent 1ef781f commit 8a48c83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+124
-3284
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "deps/gtest"]
22
path = deps/gtest
33
url = git://github.com/cpp-netlib/gtest
4+
[submodule "uri"]
5+
path = uri
6+
url = git://github.com/cpp-netlib/uri

CMakeLists.txt

+18-25
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,15 @@ endif()
6868
message("C++ Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
6969
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}")
7070
if (Boost_FOUND)
71-
if (MSVC)
72-
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
73-
endif(MSVC)
74-
if (WIN32)
75-
add_definitions(-D_WIN32_WINNT=0x0501)
76-
endif(WIN32)
77-
include_directories(${Boost_INCLUDE_DIRS})
78-
if(CPP-NETLIB_BUILD_TESTS)
79-
enable_testing()
80-
endif()
81-
#add_subdirectory(libs/network/src)
82-
if(CPP-NETLIB_BUILD_TESTS)
83-
enable_testing()
84-
#add_subdirectory(libs/network/test)
85-
if (NOT MSVC)
86-
#add_subdirectory(libs/mime/test)
87-
endif(NOT MSVC)
88-
endif()
89-
if(CPP-NETLIB_BUILD_EXAMPLES)
90-
#add_subdirectory(libs/network/example)
91-
endif()
71+
if (MSVC)
72+
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
73+
endif(MSVC)
74+
if (WIN32)
75+
add_definitions(-D_WIN32_WINNT=0x0501)
76+
endif(WIN32)
77+
include_directories(${Boost_INCLUDE_DIRS})
9278
endif(Boost_FOUND)
9379

94-
if(CPP-NETLIB_BUILD_TESTS)
95-
enable_testing()
96-
endif()
97-
9880
message(STATUS "CPP-NETLIB Options selected:")
9981
message(STATUS " CPP-NETLIB_BUILD_SHARED_LIBS: ${CPP-NETLIB_BUILD_SHARED_LIBS}\t(Build cpp-netlib as shared libraries: OFF, ON)")
10082
message(STATUS " CPP-NETLIB_BUILD_TESTS: ${CPP-NETLIB_BUILD_TESTS}\t(Build the unit tests: ON, OFF)")
@@ -107,6 +89,17 @@ message(STATUS " CPP-NETLIB_DISABLE_LOGGING: ${CPP-NETLIB_DISABLE_LOGGING}\t(
10789
# The code following this point is for the new directory structure
10890
#
10991

92+
if(CPP-NETLIB_BUILD_TESTS)
93+
enable_testing()
94+
add_subdirectory(deps/gtest)
95+
set(GTEST_ROOT ${CPP-NETLIB_SOURCE_DIR}/deps/gtest)
96+
set(GTEST_FOUND ON)
97+
set(GTEST_INCLUDE_DIRS ${GTEST_ROOT}/include)
98+
set(GTEST_LIBRARIES gtest)
99+
set(GTEST_MAIN_LIBRARIES gtest_main)
100+
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
101+
endif()
102+
110103
add_subdirectory(uri)
111104
add_subdirectory(message)
112105
add_subdirectory(logging)

contrib/http_examples/CMakeLists.txt

+16-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endif()
2020
add_executable(simple_wget simple_wget.cpp)
2121
add_executable(atom_reader atom/atom.cpp atom/main.cpp)
2222
add_executable(rss_reader rss/rss.cpp rss/main.cpp)
23-
add_executable(twitter_search twitter/search.cpp)
23+
#add_executable(twitter_search twitter/search.cpp)
2424
#add_executable(hello_world_server http/hello_world_server.cpp)
2525
add_executable(hello_world_client http/hello_world_client.cpp)
2626
#if (UNIX)
@@ -81,19 +81,19 @@ target_link_libraries(rss_reader
8181
cppnetlib-http-client-connections
8282
${CPP-NETLIB_LOGGING_LIB})
8383

84-
target_link_libraries(twitter_search
85-
${BOOST_CLIENT_LIBS}
86-
${CMAKE_THREAD_LIBS_INIT}
87-
cppnetlib-uri
88-
cppnetlib-message
89-
cppnetlib-message-directives
90-
cppnetlib-message-wrappers
91-
cppnetlib-http-message-wrappers
92-
cppnetlib-http-message
93-
cppnetlib-constants
94-
cppnetlib-http-client
95-
cppnetlib-http-client-connections
96-
${CPP-NETLIB_LOGGING_LIB})
84+
#target_link_libraries(twitter_search
85+
# ${BOOST_CLIENT_LIBS}
86+
# ${CMAKE_THREAD_LIBS_INIT}
87+
# cppnetlib-uri
88+
# cppnetlib-message
89+
# cppnetlib-message-directives
90+
# cppnetlib-message-wrappers
91+
# cppnetlib-http-message-wrappers
92+
# cppnetlib-http-message
93+
# cppnetlib-constants
94+
# cppnetlib-http-client
95+
# cppnetlib-http-client-connections
96+
# ${CPP-NETLIB_LOGGING_LIB})
9797

9898
#target_link_libraries(hello_world_server
9999
# ${BOOST_SERVER_LIBS}
@@ -120,7 +120,7 @@ if (OPENSSL_FOUND)
120120
target_link_libraries(simple_wget ${OPENSSL_LIBRARIES})
121121
target_link_libraries(atom_reader ${OPENSSL_LIBRARIES})
122122
target_link_libraries(rss_reader ${OPENSSL_LIBRARIES})
123-
target_link_libraries(twitter_search ${OPENSSL_LIBRARIES})
123+
#target_link_libraries(twitter_search ${OPENSSL_LIBRARIES})
124124
#target_link_libraries(hello_world_server ${OPENSSL_LIBRARIES})
125125
target_link_libraries(hello_world_client ${OPENSSL_LIBRARIES})
126126
endif (OPENSSL_FOUND)
@@ -136,7 +136,7 @@ endif (OPENSSL_FOUND)
136136
set_target_properties(simple_wget PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
137137
set_target_properties(atom_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
138138
set_target_properties(rss_reader PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
139-
set_target_properties(twitter_search PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
139+
#set_target_properties(twitter_search PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
140140
#set_target_properties(hello_world_server PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
141141
set_target_properties(hello_world_client PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CPP-NETLIB_BINARY_DIR}/example)
142142
#if (UNIX)

contrib/http_examples/simple_wget.cpp

+27-23
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,43 @@ namespace http = network::http;
2727

2828
namespace {
2929
std::string get_filename(const network::uri &url) {
30-
std::string path = network::path(url);
31-
std::size_t index = path.find_last_of('/');
32-
std::string filename = path.substr(index + 1);
30+
auto path = url.path();
31+
if (path) {
32+
auto path_str = std::string(*path);
33+
auto index = path_str.find_last_of('/');
34+
auto filename = path_str.substr(index + 1);
3335
return filename.empty()? "index.html" : filename;
36+
}
37+
return "index.html";
3438
}
3539
} // namespace
3640

3741

3842
int
3943
main(int argc, char *argv[]) {
4044

41-
if (argc != 2) {
42-
std::cerr << "Usage: " << argv[0] << " url" << std::endl;
43-
return 1;
44-
}
45+
if (argc != 2) {
46+
std::cerr << "Usage: " << argv[0] << " url" << std::endl;
47+
return 1;
48+
}
4549

46-
try {
47-
http::client client;
48-
http::client::request request(argv[1]);
49-
http::client::response response = client.get(request);
50+
try {
51+
http::client client;
52+
http::client::request request(argv[1]);
53+
http::client::response response = client.get(request);
5054

51-
network::uri uri;
52-
request.get_uri(uri);
53-
std::string filename = get_filename(uri);
54-
std::cout << "Saving to: " << filename << std::endl;
55-
std::ofstream ofs(filename.c_str());
56-
ofs << static_cast<std::string>(body(response)) << std::endl;
57-
}
58-
catch (std::exception &e) {
59-
std::cerr << e.what() << std::endl;
60-
return 1;
61-
}
55+
network::uri uri;
56+
request.get_uri(uri);
57+
std::string filename = get_filename(uri);
58+
std::cout << "Saving to: " << filename << std::endl;
59+
std::ofstream ofs(filename.c_str());
60+
ofs << static_cast<std::string>(body(response)) << std::endl;
61+
}
62+
catch (std::exception &e) {
63+
std::cerr << e.what() << std::endl;
64+
return 1;
65+
}
6266

63-
return 0;
67+
return 0;
6468
}
6569
//]

contrib/http_examples/twitter/search.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ int main(int argc, char *argv[]) {
2929
network::uri base_uri("http://search.twitter.com/search.json");
3030

3131
std::cout << "Searching Twitter for query: " << argv[1] << std::endl;
32-
network::uri search;
33-
search << base_uri << network::query("q", network::encoded(argv[1]));
34-
http::client::request request(search);
32+
33+
network::uri_builder builder(base_uri);
34+
builder.query("q", argv[1]))
35+
http::client::request request(builder.uri());
3536
http::client::response response = client.get(request);
3637

3738
Document d;

http/src/network/protocol/http/algorithms/linearize.hpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <network/constants.hpp>
1515
#include <boost/concept/requires.hpp>
1616
#include <boost/optional.hpp>
17+
#include <boost/lexical_cast.hpp>
1718
#include <boost/range/algorithm/copy.hpp>
1819

1920
namespace network {
@@ -38,8 +39,8 @@ struct linearize_header {
3839
typedef std::ostringstream output_stream;
3940
typedef constants consts;
4041
output_stream header_line;
41-
header_line << name(header)
42-
<< consts::colon() << consts::space()
42+
header_line << name(header)
43+
<< consts::colon() << consts::space()
4344
<< value(header) << consts::crlf();
4445
return header_line.str();
4546
}
@@ -50,16 +51,16 @@ BOOST_CONCEPT_REQUIRES(
5051
((ClientRequest<Request>)),
5152
(OutputIterator)
5253
) linearize(
53-
Request const & request,
54+
Request const & request,
5455
std::string const & method,
55-
unsigned version_major,
56-
unsigned version_minor,
56+
unsigned version_major,
57+
unsigned version_minor,
5758
OutputIterator oi
58-
)
59+
)
5960
{
6061
typedef constants consts;
6162
typedef std::string string_type;
62-
static string_type
63+
static string_type
6364
http_slash = consts::http_slash()
6465
, accept = consts::accept()
6566
, accept_mime = consts::default_accept_mime()
@@ -76,7 +77,7 @@ BOOST_CONCEPT_REQUIRES(
7677
*oi = consts::space_char();
7778
{
7879
std::string path_ = path(request);
79-
if (path_.empty() || path_[0] != consts::slash_char())
80+
if (path_.empty() || path_[0] != consts::slash_char())
8081
*oi = consts::slash_char();
8182
boost::copy(path_, oi);
8283
}
@@ -156,8 +157,8 @@ BOOST_CONCEPT_REQUIRES(
156157
auto body_data = network::body(request);
157158
return std::copy(body_data.begin(), body_data.end(), oi);
158159
}
159-
160+
160161
} // namespace http
161162
} // namespace network
162-
163+
163164
#endif /* NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028 */

http/src/network/protocol/http/client/connection/simple_connection_factory.ipp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <network/uri/uri_io.hpp>
1919
#endif
2020
#include <boost/algorithm/string/case_conv.hpp>
21+
#include <boost/algorithm/string/predicate.hpp>
2122

2223
#include <network/protocol/http/message/wrappers/uri.hpp>
2324

@@ -39,7 +40,7 @@ struct simple_connection_factory_pimpl {
3940
NETWORK_MESSAGE("simple_connection_factory_pimpl::create_connection(...)");
4041
::network::uri uri_ = http::uri(request);
4142
NETWORK_MESSAGE("destination: " << uri_);
42-
bool https = boost::algorithm::to_lower_copy(::network::scheme(uri_)) == "https";
43+
bool https = boost::algorithm::to_lower_copy(std::string(*uri_.scheme())) == "https";
4344
return std::make_shared<http_async_connection>(
4445
res_delegate_factory_->create_resolver_delegate(service, options.cache_resolved()),
4546
conn_delegate_factory_->create_connection_delegate(service, https, options),

http/src/network/protocol/http/client/facade.ipp

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <network/protocol/http/client/facade.hpp>
1111
#include <network/detail/debug.hpp>
12+
#include <boost/lexical_cast.hpp>
1213

1314
namespace network {
1415
namespace http {

http/src/network/protocol/http/message/wrappers/anchor.ipp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ anchor_wrapper::anchor_wrapper(request_base const & request)
2020
anchor_wrapper::operator std::string () const {
2121
::network::uri uri_;
2222
request_.get_uri(uri_);
23-
return fragment(uri_);
23+
auto fragment = uri_.fragment();
24+
return fragment? std::string(*fragment) : std::string();
2425
}
2526

2627
} // namespace http

http/src/network/protocol/http/message/wrappers/host.ipp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ host_wrapper::host_wrapper(request_base const & request)
1818
host_wrapper::operator std::string () const {
1919
::network::uri uri_;
2020
request_.get_uri(uri_);
21-
return host(uri_);
21+
auto host = uri_.host();
22+
return host? std::string(*host) : std::string("");
2223
}
2324

2425
} // namespace http

http/src/network/protocol/http/message/wrappers/path.ipp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ path_wrapper::path_wrapper(request_base const & request)
1818
path_wrapper::operator std::string () const {
1919
::network::uri uri_;
2020
request_.get_uri(uri_);
21-
return path(uri_);
21+
auto path = uri_.path();
22+
return path? std::string(*path) : std::string("");
2223
}
2324

2425
} // namespace http

http/src/network/protocol/http/message/wrappers/port.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define NETWORK_PROTOCOL_HTTP_MESSAGE_PORT_HPP_20100618
1010

1111
#include <network/protocol/http/request/request_base.hpp>
12+
#include <boost/cstdint.hpp>
1213
#include <boost/optional.hpp>
1314

1415
namespace network { namespace http {

http/src/network/protocol/http/message/wrappers/port.ipp

+11-6
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,27 @@ port_wrapper::port_wrapper(request_base const & request)
1919
port_wrapper::operator boost::uint16_t () const {
2020
::network::uri uri_;
2121
request_.get_uri(uri_);
22-
boost::optional<boost::uint16_t> optional_port = port_us(uri_);
22+
auto optional_port = uri_.port();
2323
if (!optional_port) {
24-
std::string scheme_ = scheme(uri_);
25-
if (scheme_ == "http") {
24+
auto scheme_ = uri_.scheme();
25+
assert(scheme_);
26+
if (*scheme_ == "http") {
2627
return 80u;
27-
} else if (scheme_ == "https") {
28+
} else if (*scheme_ == "https") {
2829
return 443u;
2930
}
3031
}
31-
return optional_port ? *optional_port : 80u;
32+
return std::stoul(std::string(*optional_port));
3233
}
3334

3435
port_wrapper::operator boost::optional<boost::uint16_t> () const {
3536
::network::uri uri_;
3637
request_.get_uri(uri_);
37-
return port_us(uri_);
38+
auto optional_port = uri_.port();
39+
if (!optional_port) {
40+
return boost::optional<boost::uint16_t>();
41+
}
42+
return std::stoul(std::string(*optional_port));
3843
}
3944

4045
} // namespace http

http/src/network/protocol/http/message/wrappers/query.ipp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ query_wrapper::query_wrapper(request_base const & request)
1818
query_wrapper::operator std::string () const {
1919
::network::uri uri_;
2020
request_.get_uri(uri_);
21-
return query(uri_);
21+
auto query = uri_.query();
22+
return query? std::string(*query) : std::string("");
2223
}
2324

2425
} // namespace http

http/src/network/protocol/http/request/request.ipp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct request_pimpl {
4747
}
4848

4949
void set_uri(std::string const & uri) {
50-
uri_ = uri;
50+
set_uri(::network::uri(uri));
5151
}
5252

5353
void set_uri(::network::uri const & uri) {

0 commit comments

Comments
 (0)