Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into garethsb-http-ssl_c…
Browse files Browse the repository at this point in the history
…ontext_callback
  • Loading branch information
BillyONeal committed Mar 19, 2019
2 parents 43773b9 + a917bd4 commit 6225905
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 41 deletions.
47 changes: 36 additions & 11 deletions Build_android/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ set -e

DO_BOOST=1
DO_OPENSSL=1
DO_CMAKE=1
DO_CPPRESTSDK=1

BOOSTVER=1.65.1
OPENSSLVER=1.0.2k
BOOSTVER=1.69.0
OPENSSLVER=1.1.0j
CMAKEVER=3.14.0

API=15
STL=c++_static
STL=c++_shared

function usage {
echo "Usage: $0 [--skip-boost] [--skip-openssl] [--skip-cpprestsdk] [-h] [--ndk <android-ndk>]"
Expand All @@ -51,6 +53,9 @@ do
"--skip-openssl")
DO_OPENSSL=0
;;
"--skip-cmake")
DO_CMAKE=0
;;
"--skip-cpprestsdk")
DO_CPPRESTSDK=0
;;
Expand All @@ -59,6 +64,11 @@ do
DO_BOOST=1
BOOSTVER=$1
;;
"--cmake")
shift
DO_CMAKE=1
CMAKEVER=$1
;;
"--openssl")
shift
DO_OPENSSL=1
Expand Down Expand Up @@ -130,8 +140,8 @@ if [ "${DO_OPENSSL}" == "1" ]; then (
if [ ! -d "openssl" ]; then mkdir openssl; fi
cd openssl
cp -af "${DIR}/openssl/." .
make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_GCC_VERSION=4.9 ANDROID_ABI=armeabi-v7a OPENSSL_PREFIX=armeabi-v7a OPENSSL_VERSION=$OPENSSLVER
make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_GCC_VERSION=4.9 ANDROID_ABI=x86 OPENSSL_PREFIX=x86 OPENSSL_VERSION=$OPENSSLVER
make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_ABI=armeabi-v7a OPENSSL_PREFIX=armeabi-v7a OPENSSL_VERSION=$OPENSSLVER -j $NCPU
make all ANDROID_NDK="${NDK_DIR}" ANDROID_TOOLCHAIN=clang ANDROID_ABI=x86 OPENSSL_PREFIX=x86 OPENSSL_VERSION=$OPENSSLVER -j $NCPU
) fi

# -----
Expand All @@ -143,7 +153,7 @@ if [ "${DO_OPENSSL}" == "1" ]; then (
if [ "${DO_BOOST}" == "1" ]; then (
if [ ! -d 'Boost-for-Android' ]; then git clone https://github.com/moritz-wundke/Boost-for-Android; fi
cd Boost-for-Android
git checkout 84973078a3d7668067d422d4654696ef59ab9d6d
git checkout 1356b87fed389b4abf1ff671adec0b899877174b
PATH="$PATH:$NDK_DIR" \
CXXFLAGS="-std=gnu++11" \
./build-android.sh \
Expand All @@ -153,23 +163,38 @@ if [ "${DO_BOOST}" == "1" ]; then (
"${NDK_DIR}" || exit 1
) fi

# ------
# CMake
# ------
# We update CMake because the version included with Ubuntu is too old to handle Boost 1.69.

if [ "${DO_CMAKE}" == "1" ]; then (
if [ ! -d "cmake-${CMAKEVER}" ]; then wget https://github.com/Kitware/CMake/releases/download/v${CMAKEVER}/cmake-${CMAKEVER}-Linux-x86_64.sh; fi
chmod +x cmake-${CMAKEVER}-Linux-x86_64.sh
rm -rf cmake-${CMAKEVER}
mkdir cmake-${CMAKEVER}
cd cmake-${CMAKEVER}
../cmake-${CMAKEVER}-Linux-x86_64.sh --skip-license
) fi

# ----------
# casablanca
# ----------

if [ "${DO_CPPRESTSDK}" == "1" ]; then
# Use the builtin CMake toolchain configuration that comes with the NDK
function build_cpprestsdk { (
mkdir -p $1
cd $1
cmake "${DIR}/.." \
rm -rf $1
./cmake-${CMAKEVER}/bin/cmake \
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
-DANDROID_NDK="${ANDROID_NDK}" \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_ABI=$2 \
-DBOOST_VERSION="${BOOSTVER}" \
-DCMAKE_BUILD_TYPE=$3
make -j $NCPU
-DCMAKE_BUILD_TYPE=$3 \
-S "${DIR}/.." \
-B $1
make -j $NCPU -C $1
) }

# Build the cpprestsdk for each target configuration
Expand Down
76 changes: 76 additions & 0 deletions Build_android/openssl/openssl-1.1.0j.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
This patch applies several changes that enable OpenSSL 1.1.0g to be built
for Android using either Clang or GCC toolchains.

diff -Naur org/Configurations/10-main.conf mod/Configurations/10-main.conf
--- org/Configurations/10-main.conf 2017-11-02 07:29:01.000000000 -0700
+++ mod/Configurations/10-main.conf 2018-01-18 10:59:41.675138500 -0800
@@ -910,15 +910,27 @@
# systems are perfectly capable of executing binaries targeting
# Froyo. Keep in mind that in the nutshell Android builds are
# about JNI, i.e. shared libraries, not applications.
- cflags => add(picker(default => "-mandroid -fPIC --sysroot=\$(CROSS_SYSROOT) -Wa,--noexecstack")),
+ cflags => add(picker(default => "-mandroid -fPIC --sysroot=\$(ANDROID_LINK_SYSROOT) -isystem \$(ANDROID_SYSROOT)/usr/include -isystem \$(ANDROID_SYSROOT)/usr/include/\$(ANDROID_TRIPLE) -D__ANDROID_API__=\$(ANDROID_API) -Wa,--noexecstack")),
bin_cflags => "-pie",
},
+ "android-clang" => {
+ inherit_from => [ "linux-generic32" ],
+ cc => "clang",
+ cflags => add(picker(default => "-fPIC --gcc-toolchain=\$(ANDROID_GCC_TOOLCHAIN) --sysroot=\$(ANDROID_LINK_SYSROOT) -isystem \$(ANDROID_SYSROOT)/usr/include -isystem \$(ANDROID_SYSROOT)/usr/include/\$(ANDROID_TRIPLE) -D__ANDROID_API__=\$(ANDROID_API) -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Qunused-arguments -Wa,--noexecstack")),
+},
"android-x86" => {
inherit_from => [ "android", asm("x86_asm") ],
cflags => add(picker(release => "-fomit-frame-pointer")),
bn_ops => "BN_LLONG",
perlasm_scheme => "android",
},
+ "android-x86-clang" => {
+ inherit_from => [ "android-clang", asm("x86_asm") ],
+ cflags => add(picker(default => "-target i686-none-linux-android",
+ release => "-fomit-frame-pointer")),
+ bn_ops => "BN_LLONG",
+ perlasm_scheme => "android",
+ },
################################################################
# Contemporary Android applications can provide multiple JNI
# providers in .apk, targeting multiple architectures. Among
@@ -943,20 +955,38 @@
"android-armeabi" => {
inherit_from => [ "android", asm("armv4_asm") ],
},
+ "android-armeabi-clang" => {
+ inherit_from => [ "android-clang", asm("armv4_asm") ],
+ cflags => add("-target armv7-none-linux-androideabi"),
+ },
"android-mips" => {
inherit_from => [ "android", asm("mips32_asm") ],
perlasm_scheme => "o32",
},
-
+ "android-mips-clang" => {
+ inherit_from => [ "android-clang", asm("mips32_asm") ],
+ cflags => add("-target mipsel-none-linux-android"),
+ perlasm_scheme => "o32",
+ },
"android64" => {
inherit_from => [ "linux-generic64" ],
- cflags => add(picker(default => "-mandroid -fPIC --sysroot=\$(CROSS_SYSROOT) -Wa,--noexecstack")),
+ cflags => add(picker(default => "-mandroid -fPIC --sysroot=\$(ANDROID_LINK_SYSROOT) -isystem \$(ANDROID_SYSROOT)/usr/include -isystem \$(ANDROID_SYSROOT)/usr/include/\$(ANDROID_TRIPLE) -D__ANDROID_API__=\$(ANDROID_API) -Wa,--noexecstack")),
bin_cflags => "-pie",
},
+ "android64-clang" => {
+ inherit_from => [ "linux-generic64" ],
+ cc => "clang",
+ cflags => add(picker(default => "-fPIC --gcc-toolchain=\$(ANDROID_GCC_TOOLCHAIN) --sysroot=\$(ANDROID_LINK_SYSROOT) -isystem \$(ANDROID_SYSROOT)/usr/include -isystem \$(ANDROID_SYSROOT)/usr/include/\$(ANDROID_TRIPLE) -D__ANDROID_API__=\$(ANDROID_API) -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Qunused-arguments -Wa,--noexecstack")),
+ },
"android64-aarch64" => {
inherit_from => [ "android64", asm("aarch64_asm") ],
perlasm_scheme => "linux64",
},
+ "android64-aarch64-clang" => {
+ inherit_from => [ "android64-clang", asm("aarch64_asm") ],
+ cflags => add("-target aarch64-none-linux-android"),
+ perlasm_scheme => "linux64",
+ },

#### *BSD
"BSD-generic32" => {
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
project(cpprestsdk-root NONE)

enable_testing()
add_subdirectory(Release)
4 changes: 3 additions & 1 deletion Release/cmake/cpprest_find_boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ function(cpprest_find_boost)
endif()
elseif(ANDROID)
set(Boost_COMPILER "-clang")
if(ARM)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/armeabi-v7a" CACHE INTERNAL "")
set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/armeabi-v7a/lib" CACHE INTERNAL "")
set(Boost_ARCHITECTURE "-a32" CACHE INTERNAL "")
else()
set(BOOST_ROOT "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/x86" CACHE INTERNAL "")
set(BOOST_LIBRARYDIR "${CMAKE_BINARY_DIR}/../Boost-for-Android/build/out/x86/lib" CACHE INTERNAL "")
set(Boost_ARCHITECTURE "-x32" CACHE INTERNAL "")
endif()
cpprestsdk_find_boost_android_package(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS random system thread filesystem chrono atomic)
elseif(UNIX)
Expand Down
9 changes: 8 additions & 1 deletion Release/include/cpprest/filestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,19 @@ class basic_file_buffer : public details::streambuf_state_manager<_CharType>
if (mode == std::ios_base::in)
{
m_readOps.wait();
size_t current_pos = static_cast<size_t>(-1);
switch (way)
{
case std::ios_base::beg: return (pos_type)_seekrdpos_fsb(m_info, size_t(offset), sizeof(_CharType));
case std::ios_base::cur:
return (pos_type)_seekrdpos_fsb(m_info, size_t(m_info->m_rdpos + offset), sizeof(_CharType));
case std::ios_base::end: return (pos_type)_seekrdtoend_fsb(m_info, int64_t(offset), sizeof(_CharType));
case std::ios_base::end:
current_pos = _seekrdtoend_fsb(m_info, int64_t(offset), sizeof(_CharType));
if (current_pos == static_cast<size_t>(-1))
{
return -1;
}
return (pos_type)current_pos;
default:
// Fail on invalid input (_S_ios_seekdir_end)
assert(false);
Expand Down
24 changes: 15 additions & 9 deletions Release/src/http/common/http_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,25 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
{
const auto& completionEvent = _get_data_available();
auto closeTask = pplx::task_from_result();

if (exceptionPtr == std::exception_ptr())
if (m_default_outstream)
{
if (m_default_outstream)
// if the outstream is one we created by default on the customer's behalf, try to close it
auto& out = outstream();
if (out.is_valid())
{
closeTask = outstream().close();
if (exceptionPtr == std::exception_ptr())
{
closeTask = out.close();
}
else
{
closeTask = out.close(exceptionPtr);
}
}
}

if (exceptionPtr == std::exception_ptr())
{
inline_continuation(closeTask, [completionEvent, body_size](pplx::task<void> t) {
try
{
Expand All @@ -459,11 +470,6 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
}
else
{
if (outstream().is_valid())
{
closeTask = outstream().close(exceptionPtr);
}

inline_continuation(closeTask, [completionEvent, exceptionPtr](pplx::task<void> t) {
// If closing stream throws an exception ignore since we already have an error.
try
Expand Down
15 changes: 15 additions & 0 deletions Release/src/streams/fileio_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,11 +905,26 @@ size_t __cdecl _seekrdtoend_fsb(_In_ streams::details::_file_info* info, int64_t
fInfo->m_bufoff = fInfo->m_buffill = fInfo->m_bufsize = 0;
}

#ifdef _WIN64
LARGE_INTEGER filesize;
filesize.QuadPart = 0;

BOOL result = GetFileSizeEx(fInfo->m_handle, &filesize);
if (FALSE == result)
{
return static_cast<size_t>(-1);
}
else
{
fInfo->m_rdpos = static_cast<size_t>(filesize.QuadPart) / char_size;
}
#else
auto newpos = SetFilePointer(fInfo->m_handle, (LONG)(offset * char_size), nullptr, FILE_END);

if (newpos == INVALID_SET_FILE_POINTER) return static_cast<size_t>(-1);

fInfo->m_rdpos = static_cast<size_t>(newpos) / char_size;
#endif

return fInfo->m_rdpos;
}
Expand Down
10 changes: 0 additions & 10 deletions Release/tests/functional/http/client/connections_and_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,7 @@ SUITE(connections_and_errors)
http_response rsp = client.request(msg).get();

// The response body should timeout and we should receive an exception
#ifndef _WIN32
// CodePlex 295
VERIFY_THROWS(rsp.content_ready().wait(), http_exception);
#else
VERIFY_THROWS_HTTP_ERROR_CODE(rsp.content_ready().wait(), std::errc::timed_out);
#endif
}

buf.close(std::ios_base::out).wait();
Expand Down Expand Up @@ -261,12 +256,7 @@ SUITE(connections_and_errors)

// The response body should timeout and we should receive an exception
auto readTask = rsp.body().read_to_end(streams::producer_consumer_buffer<uint8_t>());
#ifndef _WIN32
// CodePlex 295
VERIFY_THROWS(readTask.get(), http_exception);
#else
VERIFY_THROWS_HTTP_ERROR_CODE(readTask.wait(), std::errc::timed_out);
#endif
}

buf.close(std::ios_base::out).wait();
Expand Down
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- script: .\vcpkg\bootstrap-vcpkg.bat
displayName: Bootstrap vcpkg
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --vcpkg-root .\vcpkg
displayName: vcpkg install dependencies
- script: mkdir build.common
displayName: Make Build Directory
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
steps:
- script: .\vcpkg\bootstrap-vcpkg.bat
displayName: Bootstrap vcpkg
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --triplet x64-windows
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --triplet x64-windows --vcpkg-root .\vcpkg
displayName: vcpkg install dependencies
- script: mkdir build.common
displayName: Make Build Directory
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
steps:
- script: .\vcpkg\bootstrap-vcpkg.bat
displayName: Bootstrap vcpkg
- script: .\vcpkg\vcpkg.exe install zlib --triplet x64-uwp
- script: .\vcpkg\vcpkg.exe install zlib --triplet x64-uwp --vcpkg-root .\vcpkg
displayName: vcpkg install dependencies
- script: mkdir build.common
displayName: Make Build Directory
Expand All @@ -90,7 +90,7 @@ jobs:
steps:
- script: .\vcpkg\bootstrap-vcpkg.bat
displayName: Bootstrap vcpkg
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --vcpkg-root .\vcpkg
displayName: vcpkg install dependencies
- script: mkdir build.common
displayName: Make Build Directory
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
steps:
- script: .\vcpkg\bootstrap-vcpkg.bat
displayName: Bootstrap vcpkg
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --triplet x64-windows
- script: .\vcpkg\vcpkg.exe install zlib openssl boost-system boost-date-time boost-regex boost-interprocess websocketpp brotli --triplet x64-windows --vcpkg-root .\vcpkg
displayName: vcpkg install dependencies
- script: mkdir build.common
displayName: Make Build Directory
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
sudo apt-get -y update
sudo apt-get install g++-7 ninja-build -y
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli
./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli --vcpkg-root ./vcpkg
displayName: Vcpkg install dependencies
- script: |
mkdir build.debug
Expand Down Expand Up @@ -284,7 +284,7 @@ jobs:
- script: |
brew install gcc ninja
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli
./vcpkg/vcpkg install zlib openssl boost-system boost-date-time boost-regex websocketpp boost-thread boost-filesystem boost-random boost-chrono boost-interprocess brotli --vcpkg-root ./vcpkg
displayName: Vcpkg install dependencies
- script: |
mkdir build.debug
Expand Down
2 changes: 1 addition & 1 deletion vcpkg
Submodule vcpkg updated 918 files

0 comments on commit 6225905

Please sign in to comment.