Commit 05a8f44a authored by Jakob Otto's avatar Jakob Otto

Merge branch 'master' into topic/ip-endpoint

parents 6acea262 097df535
......@@ -4,6 +4,14 @@ project(caf C CXX)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
get_directory_property(_parent PARENT_DIRECTORY)
if(_parent)
set(caf_is_subproject ON)
else()
set(caf_is_subproject OFF)
endif()
unset(_parent)
# Be nice to VIM users and Clang tools.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
......@@ -50,7 +58,9 @@ else()
endif()
# add helper target that simplifies re-running configure
add_custom_target(configure COMMAND ${CMAKE_CURRENT_BINARY_DIR}/config.status)
if(NOT caf_is_subproject)
add_custom_target(configure COMMAND ${CMAKE_CURRENT_BINARY_DIR}/config.status)
endif()
################################################################################
# utility functions #
......@@ -159,14 +169,14 @@ endif()
# set module path appropriately
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# set binary output path if not defined by user
if(EXECUTABLE_OUTPUT_PATH STREQUAL "")
if(NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/bin")
endif()
# set library output path if not defined by user, but always set
# library output path to binary output path for Xcode projects
if(CMAKE_GENERATOR STREQUAL "Xcode")
set(LIBRARY_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}")
elseif(LIBRARY_OUTPUT_PATH STREQUAL "")
elseif(NOT LIBRARY_OUTPUT_PATH)
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib")
endif()
......@@ -404,12 +414,15 @@ install(DIRECTORY libcaf_test/caf/ DESTINATION include/caf
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
# add uninstall target
add_custom_target(uninstall
# add uninstall target if it does not exist yet
if(NOT TARGET uninstall)
add_custom_target(uninstall)
endif()
add_custom_command(TARGET uninstall
PRE_BUILD
COMMAND "${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
################################################################################
# set inclue paths for subprojects #
################################################################################
......
......@@ -88,7 +88,7 @@ config = [
],
// Configures what binary the coverage report uses and what paths to exclude.
coverage: [
binary: 'build/caf-test',
binary: 'build/bin/caf-test',
relativeExcludePaths: [
'examples',
'tools',
......
......@@ -91,7 +91,8 @@ foreach (comp ${CAF_FIND_COMPONENTS})
/usr/local/lib
/opt/local/lib
/sw/lib
${CMAKE_INSTALL_PREFIX}/lib)
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_BUILD_TYPE})
mark_as_advanced(CAF_LIBRARY_${UPPERCOMP})
if ("${CAF_LIBRARY_${UPPERCOMP}}"
STREQUAL "CAF_LIBRARY_${UPPERCOMP}-NOTFOUND")
......
......@@ -26,6 +26,7 @@ set(LIBCAF_CORE_SRCS
src/actor_system.cpp
src/actor_system_config.cpp
src/append_hex.cpp
src/append_percent_encoded.cpp
src/atom.cpp
src/attachable.cpp
src/behavior.cpp
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/detail/append_hex.hpp"
#include "caf/fwd.hpp"
namespace caf {
namespace detail {
// Escapes all reserved characters according to RFC 3986 in `x` and
// adds the encoded string to `str`.
void append_percent_encoded(std::string& str, string_view x,
bool is_path = false);
} // namespace detail
} // namespace caf
......@@ -76,10 +76,6 @@ public:
/// Assembles the human-readable string representation for this URI.
void assemble_str();
// Escapes all reserved characters according to RFC 3986 in `x` and
// adds the encoded string to `str`.
void add_encoded(string_view x, bool is_path = false);
// -- friend functions -------------------------------------------------------
friend void intrusive_ptr_add_ref(const uri_impl* p);
......
......@@ -134,6 +134,9 @@ typename Inspector::result_type inspect(Inspector& f, uri::authority_type& x) {
/// @relates uri
std::string to_string(const uri& x);
/// @relates uri
std::string to_string(const uri::authority_type& x);
/// @relates uri
error parse(string_view str, uri& dest);
......
......@@ -16,7 +16,7 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/stringification_inspector.hpp"
#include "caf/detail/append_hex.hpp"
namespace caf {
namespace detail {
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/config.hpp"
#include "caf/detail/append_hex.hpp"
#include "caf/string_view.hpp"
namespace caf {
namespace detail {
void append_percent_encoded(std::string& str, string_view x, bool is_path) {
for (auto ch : x)
switch (ch) {
case '/':
if (is_path) {
str += ch;
break;
}
CAF_ANNOTATE_FALLTHROUGH;
case ' ':
case ':':
case '?':
case '#':
case '[':
case ']':
case '@':
case '!':
case '$':
case '&':
case '\'':
case '"':
case '(':
case ')':
case '*':
case '+':
case ',':
case ';':
case '=':
str += '%';
append_hex(str, reinterpret_cast<uint8_t*>(&ch), 1);
break;
default:
str += ch;
}
}
} // namespace detail
} // namespace caf
......@@ -19,7 +19,9 @@
#include "caf/uri.hpp"
#include "caf/deserializer.hpp"
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/detail/fnv_hash.hpp"
#include "caf/detail/overload.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/detail/uri_impl.hpp"
#include "caf/error.hpp"
......@@ -101,6 +103,33 @@ std::string to_string(const uri& x) {
return result;
}
std::string to_string(const uri::authority_type& x) {
std::string str;
if (!x.userinfo.empty()) {
detail::append_percent_encoded(str, x.userinfo);
str += '@';
}
auto f = caf::detail::make_overload(
[&](const ip_address& addr) {
if (addr.embeds_v4()) {
str += to_string(addr);
} else {
str += '[';
str += to_string(addr);
str += ']';
}
},
[&](const std::string& host) {
detail::append_percent_encoded(str, host);
});
visit(f, x.host);
if (x.port != 0) {
str += ':';
str += std::to_string(x.port);
}
return str;
}
error parse(string_view str, uri& dest) {
using namespace detail::parser;
uri_builder builder;
......
......@@ -18,6 +18,7 @@
#include "caf/detail/uri_impl.hpp"
#include "caf/detail/append_percent_encoded.hpp"
#include "caf/detail/parser/read_uri.hpp"
#include "caf/error.hpp"
#include "caf/ip_address.hpp"
......@@ -39,41 +40,26 @@ uri_impl uri_impl::default_instance;
// -- modifiers ----------------------------------------------------------------
void uri_impl::assemble_str() {
add_encoded(scheme);
append_percent_encoded(str, scheme);
str += ':';
if (authority.empty()) {
CAF_ASSERT(!path.empty());
add_encoded(path, true);
append_percent_encoded(str, path, true);
} else {
str += "//";
if (!authority.userinfo.empty()) {
add_encoded(authority.userinfo);
str += '@';
}
auto addr = get_if<ip_address>(&authority.host);
if (addr == nullptr) {
add_encoded(get<std::string>(authority.host));
} else {
str += '[';
str += to_string(*addr);
str += ']';
}
if (authority.port != 0) {
str += ':';
str += std::to_string(authority.port);
}
str += to_string(authority);
if (!path.empty()) {
str += '/';
add_encoded(path, true);
append_percent_encoded(str, path, true);
}
}
if (!query.empty()) {
str += '?';
auto i = query.begin();
auto add_kvp = [&](decltype(*i) kvp) {
add_encoded(kvp.first);
append_percent_encoded(str, kvp.first);
str += '=';
add_encoded(kvp.second);
append_percent_encoded(str, kvp.second);
};
add_kvp(*i);
for (++i; i != query.end(); ++i) {
......@@ -83,43 +69,7 @@ void uri_impl::assemble_str() {
}
if (!fragment.empty()) {
str += '#';
add_encoded(fragment);
}
}
void uri_impl::add_encoded(string_view x, bool is_path) {
for (auto ch : x)
switch (ch) {
case '/':
if (is_path) {
str += ch;
break;
}
CAF_ANNOTATE_FALLTHROUGH;
case ' ':
case ':':
case '?':
case '#':
case '[':
case ']':
case '@':
case '!':
case '$':
case '&':
case '\'':
case '"':
case '(':
case ')':
case '*':
case '+':
case ',':
case ';':
case '=':
str += '%';
detail::append_hex(str, reinterpret_cast<uint8_t*>(&ch), 1);
break;
default:
str += ch;
append_percent_encoded(str, fragment);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment