Skip to content

Build without CPPRestSDK #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .azure/default-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ parameters:
timeoutInMinutes: 60
cMakeRunArgs: ''
configuration: 'Release'
useCppRestSDK: true
gtestFlags: '--gtest_output=xml:$(Build.ArtifactStagingDirectory)/testOut/'

jobs:
- template: /eng/common/templates/job/job.yml
parameters:
name: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
displayName: ${{ coalesce(parameters.jobDisplayName, parameters.agentOs) }}
displayName: ${{ coalesce(parameters.jobName, parameters.agentOs) }}
dependsOn: ${{ parameters.dependsOn }}
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.agentOs, 'Windows')) }}:
Expand All @@ -38,12 +39,13 @@ jobs:
path: ./submodules/vcpkg/installed
cacheHitVar: CACHE_RESTORED
displayName: Cache vcpkg packages
condition: eq( '${{ parameters.useCppRestSDK }}', 'true' )

- ${{ parameters.beforeBuild }}

- task: CMake@1
inputs:
cmakeArgs: .. ${{ parameters.cMakeRunArgs }} -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DUSE_CPPRESTSDK=true
cmakeArgs: .. ${{ parameters.cMakeRunArgs }} -DCMAKE_TOOLCHAIN_FILE=../submodules/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=${{ parameters.configuration }} -DUSE_CPPRESTSDK=${{ parameters.useCppRestSDK }}
workingDirectory: 'build.${{ parameters.configuration }}'
displayName: Create build files
- task: CMake@1
Expand Down
16 changes: 9 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ include_directories (include)
# We need this for testing, but we might just add all the files to the test project manually
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

if(NOT WIN32)
if(APPLE)
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
list(REVERSE OPENSSL_ROOT_DIR)
if(USE_CPPRESTSDK)
if(NOT WIN32)
if(APPLE)
file(GLOB OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
list(REVERSE OPENSSL_ROOT_DIR)
endif()

find_package(OpenSSL 1.0.0 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread chrono)
endif()

find_package(OpenSSL 1.0.0 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread chrono)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
Expand Down
40 changes: 37 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ stages:
- template: .azure/default-build.yml
parameters:
agentOs: Windows
jobName: Windows_Build_Test
jobName: Windows_Build_Test_With_CppRestSDK
useCppRestSDK: true
cMakeRunArgs: '-A x64'
beforeBuild:
# check if vcpkg exists on the machine before trying to build it
Expand All @@ -57,12 +58,15 @@ stages:
- template: .azure/default-build.yml
parameters:
agentOs: macOs
jobName: Mac_Build_Test
jobName: Mac_Build_Test_With_CppRestSDK
useCppRestSDK: true
beforeBuild:
# XCode 11 doesn't play nicely with gcc, workaround by using XCode 10. We can try updating to a newer XCode in the future
# Once the problem has been resolved
- script: sudo xcode-select --switch /Applications/Xcode_10.3.app
displayName: xcode-select
- script: brew install gcc
displayName: Install gcc
- bash: "./submodules/vcpkg/bootstrap-vcpkg.sh"
condition: ne(variables.CACHE_RESTORED, 'true')
displayName: Bootstrap vcpkg
Expand All @@ -73,17 +77,47 @@ stages:
- template: .azure/default-build.yml
parameters:
agentOs: Linux
jobName: Linux_Build_Test
jobName: Linux_Build_Test_With_CppRestSDK
useCppRestSDK: true
beforeBuild:
- script: sudo vcpkg install cpprestsdk boost-system boost-chrono boost-thread --vcpkg-root ./submodules/vcpkg
condition: ne(variables.CACHE_RESTORED, 'true')
displayName: vcpkg install dependencies

- template: .azure/default-build.yml
parameters:
agentOs: Linux
jobName: Linux_Build_Test
useCppRestSDK: false

- template: .azure/default-build.yml
parameters:
agentOs: Windows
jobName: Windows_Build_Test
useCppRestSDK: false
cMakeRunArgs: '-A x64'

- template: .azure/default-build.yml
parameters:
agentOs: macOs
jobName: Mac_Build_Test
useCppRestSDK: false
beforeBuild:
# XCode 11 doesn't play nicely with gcc, workaround by using XCode 10. We can try updating to a newer XCode in the future
# Once the problem has been resolved
- script: sudo xcode-select --switch /Applications/Xcode_10.3.app
displayName: xcode-select
- script: brew install gcc
displayName: Install gcc

# Publish to the BAR
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- template: /eng/common/templates/job/publish-build-assets.yml
parameters:
dependsOn:
- Windows_Build_Test_With_CppRestSDK
- Mac_Build_Test_With_CppRestSDK
- Linux_Build_Test_With_CppRestSDK
- Windows_Build_Test
- Mac_Build_Test
- Linux_Build_Test
Expand Down
12 changes: 11 additions & 1 deletion include/signalrclient/_exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@
#else
#define SIGNALRCLIENT_API __declspec(dllimport)
#endif // SIGNALRCLIENT_EXPORTS
#endif // NO_SIGNALRCLIENT_EXPORTS
#endif // NO_SIGNALRCLIENT_EXPORTS

#ifndef _WIN32
#ifndef __cdecl
#ifdef cdecl
#define __cdecl __attribute__((cdecl))
#else
#define __cdecl
#endif // cdecl
#endif // !__cdecl
#endif // _WIN32
2 changes: 1 addition & 1 deletion include/signalrclient/hub_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace signalr

explicit hub_connection(const std::string& url, trace_level trace_level = trace_level::all,
std::shared_ptr<log_writer> log_writer = nullptr, std::shared_ptr<http_client> http_client = nullptr,
std::function<std::shared_ptr<websocket_client>()> websocket_factory = nullptr);
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory = nullptr);

std::shared_ptr<hub_connection_impl> m_pImpl;
};
Expand Down
4 changes: 2 additions & 2 deletions include/signalrclient/hub_connection_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace signalr

SIGNALRCLIENT_API hub_connection_builder& with_logging(std::shared_ptr<log_writer> logger, trace_level logLevel);

SIGNALRCLIENT_API hub_connection_builder& with_websocket_factory(std::function<std::shared_ptr<websocket_client>()> factory);
SIGNALRCLIENT_API hub_connection_builder& with_websocket_factory(std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> factory);

SIGNALRCLIENT_API hub_connection_builder& with_http_client(std::shared_ptr<http_client> http_client);

Expand All @@ -39,7 +39,7 @@ namespace signalr
std::string m_url;
std::shared_ptr<log_writer> m_logger;
trace_level m_log_level;
std::function<std::shared_ptr<websocket_client>()> m_websocket_factory;
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> m_websocket_factory;
std::shared_ptr<http_client> m_http_client;
};
}
13 changes: 9 additions & 4 deletions include/signalrclient/signalr_client_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#endif

#include "_exports.h"
#include <map>
#include <string>

namespace signalr
{
class signalr_client_config
{
#ifdef USE_CPPRESTSDK
public:
#ifdef USE_CPPRESTSDK
SIGNALRCLIENT_API void __cdecl set_proxy(const web::web_proxy &proxy);
// Please note that setting credentials does not work in all cases.
// For example, Basic Authentication fails under Win32.
Expand All @@ -28,14 +30,17 @@ namespace signalr

SIGNALRCLIENT_API web::websockets::client::websocket_client_config __cdecl get_websocket_client_config() const noexcept;
SIGNALRCLIENT_API void __cdecl set_websocket_client_config(const web::websockets::client::websocket_client_config& websocket_client_config);
#endif

SIGNALRCLIENT_API web::http::http_headers __cdecl get_http_headers() const noexcept;
SIGNALRCLIENT_API void __cdecl set_http_headers(const web::http::http_headers& http_headers);
SIGNALRCLIENT_API const std::map<std::string, std::string>& __cdecl get_http_headers() const noexcept;
SIGNALRCLIENT_API std::map<std::string, std::string>& __cdecl get_http_headers() noexcept;
SIGNALRCLIENT_API void __cdecl set_http_headers(const std::map<std::string, std::string>& http_headers);

private:
#ifdef USE_CPPRESTSDK
web::http::client::http_client_config m_http_client_config;
web::websockets::client::websocket_client_config m_websocket_client_config;
web::http::http_headers m_http_headers;
#endif
std::map<std::string, std::string> m_http_headers;
};
}
13 changes: 7 additions & 6 deletions src/signalrclient/connection_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace signalr
}

std::shared_ptr<connection_impl> connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory)
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
{
return std::shared_ptr<connection_impl>(new connection_impl(url, trace_level,
log_writer ? log_writer : std::make_shared<trace_log_writer>(), http_client, websocket_factory));
Expand All @@ -50,12 +50,14 @@ namespace signalr
}
else
{
#ifdef USE_CPPRESTSDK
m_http_client = std::unique_ptr<class http_client>(new default_http_client());
#endif
}
}

connection_impl::connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory)
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
: m_base_url(url), m_connection_state(connection_state::disconnected), m_logger(log_writer, trace_level), m_transport(nullptr),
m_message_received([](const std::string&) noexcept {}), m_disconnected([]() noexcept {})
{
Expand All @@ -73,7 +75,7 @@ namespace signalr
if (websocket_factory == nullptr)
{
#ifdef USE_CPPRESTSDK
websocket_factory = []() { return std::make_shared<default_websocket_client>(); };
websocket_factory = [](const signalr_client_config& signalr_client_config) { return std::make_shared<default_websocket_client>(signalr_client_config); };
#endif
}

Expand Down Expand Up @@ -198,9 +200,8 @@ namespace signalr
{
if (!response.accessToken.empty())
{
auto headers = connection->m_signalr_client_config.get_http_headers();
headers[_XPLATSTR("Authorization")] = utility::conversions::to_string_t("Bearer " + response.accessToken);
connection->m_signalr_client_config.set_http_headers(headers);
auto& headers = connection->m_signalr_client_config.get_http_headers();
headers["Authorization"] = "Bearer " + response.accessToken;
}
connection->start_negotiate(response.url, redirect_count + 1, callback);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/signalrclient/connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace signalr
static std::shared_ptr<connection_impl> create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer);

static std::shared_ptr<connection_impl> create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory);
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);

connection_impl(const connection_impl&) = delete;

Expand Down Expand Up @@ -70,7 +70,7 @@ namespace signalr
std::unique_ptr<http_client> http_client, std::unique_ptr<transport_factory> transport_factory);

connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer,
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>()> websocket_factory);
std::shared_ptr<http_client> http_client, std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);

void start_transport(const std::string& url, std::function<void(std::shared_ptr<transport>, std::exception_ptr)> callback);
void send_connect_request(const std::shared_ptr<transport>& transport,
Expand Down
6 changes: 5 additions & 1 deletion src/signalrclient/default_websocket_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ namespace signalr
static web::websockets::client::websocket_client_config create_client_config(const signalr_client_config& signalr_client_config) noexcept
{
auto websocket_client_config = signalr_client_config.get_websocket_client_config();
websocket_client_config.headers() = signalr_client_config.get_http_headers();
auto& websocket_headers = websocket_client_config.headers();
for (auto& header : signalr_client_config.get_http_headers())
{
websocket_headers.add(utility::conversions::to_string_t(header.first), utility::conversions::to_string_t(header.second));
}

return websocket_client_config;
}
Expand Down
2 changes: 1 addition & 1 deletion src/signalrclient/hub_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace signalr
{
hub_connection::hub_connection(const std::string& url,
trace_level trace_level, std::shared_ptr<log_writer> log_writer, std::shared_ptr<http_client> http_client,
std::function<std::shared_ptr<websocket_client>()> websocket_factory)
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
: m_pImpl(hub_connection_impl::create(url, trace_level, log_writer, http_client, websocket_factory))
{}

Expand Down
3 changes: 2 additions & 1 deletion src/signalrclient/hub_connection_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "stdafx.h"
#include "signalrclient/hub_connection_builder.h"
#include <stdexcept>

namespace signalr
{
Expand Down Expand Up @@ -55,7 +56,7 @@ namespace signalr
return *this;
}

hub_connection_builder& hub_connection_builder::with_websocket_factory(std::function<std::shared_ptr<websocket_client>()> factory)
hub_connection_builder& hub_connection_builder::with_websocket_factory(std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> factory)
{
m_websocket_factory = factory;

Expand Down
4 changes: 2 additions & 2 deletions src/signalrclient/hub_connection_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace signalr

std::shared_ptr<hub_connection_impl> hub_connection_impl::create(const std::string& url, trace_level trace_level,
const std::shared_ptr<log_writer>& log_writer, std::shared_ptr<http_client> http_client,
std::function<std::shared_ptr<websocket_client>()> websocket_factory)
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
{
auto connection = std::shared_ptr<hub_connection_impl>(new hub_connection_impl(url, trace_level, log_writer, http_client, websocket_factory));

Expand All @@ -35,7 +35,7 @@ namespace signalr

hub_connection_impl::hub_connection_impl(const std::string& url, trace_level trace_level,
const std::shared_ptr<log_writer>& log_writer, std::shared_ptr<http_client> http_client,
std::function<std::shared_ptr<websocket_client>()> websocket_factory)
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory)
: m_connection(connection_impl::create(url, trace_level, log_writer,
http_client, websocket_factory)), m_logger(log_writer, trace_level),
m_callback_manager(signalr::value(std::map<std::string, signalr::value> { { std::string("error"), std::string("connection went out of scope before invocation result was received") } })),
Expand Down
4 changes: 2 additions & 2 deletions src/signalrclient/hub_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace signalr
public:
static std::shared_ptr<hub_connection_impl> create(const std::string& url, trace_level trace_level,
const std::shared_ptr<log_writer>& log_writer, std::shared_ptr<http_client> http_client,
std::function<std::shared_ptr<websocket_client>()> websocket_factory);
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);

hub_connection_impl(const hub_connection_impl&) = delete;
hub_connection_impl& operator=(const hub_connection_impl&) = delete;
Expand All @@ -47,7 +47,7 @@ namespace signalr
private:
hub_connection_impl(const std::string& url, trace_level trace_level,
const std::shared_ptr<log_writer>& log_writer, std::shared_ptr<http_client> http_client,
std::function<std::shared_ptr<websocket_client>()> websocket_factory);
std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)> websocket_factory);

std::shared_ptr<connection_impl> m_connection;
logger m_logger;
Expand Down
6 changes: 1 addition & 5 deletions src/signalrclient/negotiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ namespace signalr
// TODO: signalr_client_config
http_request request;
request.method = http_method::POST;

for (auto& header : config.get_http_headers())
{
request.headers.insert(std::make_pair(utility::conversions::to_utf8string(header.first), utility::conversions::to_utf8string(header.second)));
}
request.headers = config.get_http_headers();

client.send(negotiate_url, request, [callback](const http_response& http_response, std::exception_ptr exception)
{
Expand Down
3 changes: 3 additions & 0 deletions src/signalrclient/negotiation_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#pragma once

#include <vector>
#include <string>

namespace signalr
{
struct available_transport
Expand Down
11 changes: 8 additions & 3 deletions src/signalrclient/signalr_client_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ namespace signalr
{
m_websocket_client_config = websocket_client_config;
}
#endif

const std::map<std::string, std::string>& signalr_client_config::get_http_headers() const noexcept
{
return m_http_headers;
}

web::http::http_headers signalr_client_config::get_http_headers() const noexcept
std::map<std::string, std::string>& signalr_client_config::get_http_headers() noexcept
{
return m_http_headers;
}

void signalr_client_config::set_http_headers(const web::http::http_headers& http_headers)
void signalr_client_config::set_http_headers(const std::map<std::string, std::string>& http_headers)
{
m_http_headers = http_headers;
}
#endif
}
Loading