Skip to content
Open
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
30 changes: 11 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


find_package(CURL)
if (CURL_FOUND)
message("Found curl")
find_package(Threads REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
set(ARBITER_CURL TRUE)
add_definitions("-DARBITER_CURL")
else()
message("Curl NOT found")
endif()
find_package(CURL REQUIRED)

find_package(OpenSSL 1.0)
if (OPENSSL_FOUND)
Expand All @@ -31,11 +21,12 @@ endif()

MESSAGE(${CMAKE_CXX_COMPILER_ID})
if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang")
add_definitions("-DUNIX")
add_definitions(${CMAKE_CXX_FLAGS} "-Wno-deprecated-declarations")
add_definitions(${CMAKE_CXX_FLAGS} "-Werror")
add_definitions(${CMAKE_CXX_FLAGS} "-Wall")
add_definitions(${CMAKE_CXX_FLAGS} "-pedantic")
add_definitions(${CMAKE_CXX_FLAGS} "-Wextra")
add_definitions(${CMAKE_CXX_FLAGS} "-pthread")
add_definitions(${CMAKE_CXX_FLAGS} "-fexceptions")
add_definitions(${CMAKE_CXX_FLAGS} "-fPIC")
Expand All @@ -47,8 +38,6 @@ endif()

include_directories("${CMAKE_CURRENT_SOURCE_DIR}")



add_subdirectory(arbiter)

set(OBJS
Expand All @@ -63,10 +52,8 @@ if (${ARBITER_ZLIB})
target_include_directories(arbiter PRIVATE "${ZLIB_INCLUDE_DIR}")
endif()

if (${ARBITER_CURL})
target_link_libraries(arbiter PUBLIC ${CURL_LIBRARIES})
target_include_directories(arbiter PRIVATE "${CURL_INCLUDE_DIR}")
endif()
target_link_libraries(arbiter PUBLIC ${CURL_LIBRARIES})
target_include_directories(arbiter PRIVATE ${CURL_INCLUDE_DIR})

if (${ARBITER_OPENSSL})
target_link_libraries(arbiter PUBLIC ${OPENSSL_LIBRARIES})
Expand All @@ -77,6 +64,11 @@ target_link_libraries(arbiter PUBLIC ${SHLWAPI})

include (${CMAKE_SOURCE_DIR}/cmake/gtest.cmake)

add_executable(arb
cmdline/cmdline.cpp)
target_link_libraries(arb PRIVATE arbiter)
target_include_directories(arb PRIVATE arbiter)

add_subdirectory(test)

install(TARGETS arbiter DESTINATION lib)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ Once the amalgamated files are integrated with your source tree, simply `#includ

Arbiter depends on [Curl](http://curl.haxx.se/libcurl/), which comes preinstalled on most UNIX-based machines. To manually link (for amalgamated usage) on Unix-based operating systems, link with `-lcurl`. Arbiter also works on Windows, but you'll have to obtain Curl yourself there.

Arbiter requires C++11.
Arbiter requires C++17.

6 changes: 0 additions & 6 deletions amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ def amalgamate_source(source_top_dir=None,
header.add_file("arbiter/third/xml/rapidxml.hpp")
header.add_file("arbiter/third/xml/xml.hpp")

if define_curl:
header.add_text("\n#pragma once")
header.add_text("#define ARBITER_CURL")
else:
print("NOT #defining ARBITER_CURL")

if bundle_json:
header.add_file("arbiter/third/json/json.hpp")
else:
Expand Down
8 changes: 2 additions & 6 deletions arbiter/arbiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ namespace
{
const std::string delimiter("://");

#ifdef ARBITER_CURL
const std::size_t concurrentHttpReqs(32);
const std::size_t httpRetryCount(8);
#endif

json getConfig(const std::string& s)
{
Expand All @@ -52,14 +50,12 @@ Arbiter::Arbiter() : Arbiter("") { }

Arbiter::Arbiter(const std::string s)
: m_config(s)
#ifdef ARBITER_CURL
, m_pool(
new http::Pool(
concurrentHttpReqs,
httpRetryCount,
getConfig(s).dump()))
#endif
{ }
{}

void Arbiter::addDriver(const std::string type, std::shared_ptr<Driver> driver)
{
Expand Down Expand Up @@ -330,7 +326,7 @@ std::shared_ptr<drivers::Http> Arbiter::getHttpDriver(const std::string path) co

LocalHandle Arbiter::getLocalHandle(
const std::string path,
const Endpoint& tempEndpoint) const
const Endpoint& /*tempEndpoint*/) const
{
const Endpoint fromEndpoint(getEndpoint(getDirname(path)));
return fromEndpoint.getLocalHandle(getBasename(path));
Expand Down
4 changes: 1 addition & 3 deletions arbiter/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ std::shared_ptr<Driver> Driver::create(

if (type == "file") return Fs::create();
if (type == "test") return Test::create();
#ifdef ARBITER_CURL
if (type == "http") return Http::create(pool);
if (type == "https") return Https::create(pool);
if (type == "s3") return S3::create(pool, entry.dump(), profile);
if (type == "az") return AZ::create(pool, entry.dump(), profile);
if (type == "dbx") return Dropbox::create(pool, entry.dump(), profile);
#ifdef ARBITER_OPENSSL
if (type == "gs") return Google::create(pool, entry.dump(), profile);
#endif
#endif
return std::shared_ptr<Driver>();
}
Expand Down Expand Up @@ -123,7 +121,7 @@ std::vector<std::string> Driver::resolve(
return results;
}

std::vector<std::string> Driver::glob(std::string path, bool verbose) const
std::vector<std::string> Driver::glob(std::string path, bool /*verbose*/) const
{
throw ArbiterError("Cannot glob driver for: " + path);
}
Expand Down
32 changes: 13 additions & 19 deletions arbiter/drivers/az.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ namespace

std::string makeLower(const std::string& in)
{
return std::accumulate(
in.begin(),
in.end(),
std::string(),
[](const std::string& out, const char c) -> std::string
{
return out + static_cast<char>(::tolower(c));
});
std::string out;
for (char c : in)
out += (char)std::tolower(c);
return out;
}

std::string extractBaseUrl(const std::string& service, const std::string& endpoint,
const std::string& account)
{
return account + "." + service + "." + endpoint + "/";
}

}

namespace drivers
Expand Down Expand Up @@ -88,7 +91,7 @@ AZ::Config::Config(const std::string s)
, m_storageAccount(extractStorageAccount(s))
, m_storageAccessKey(extractStorageAccessKey(s))
, m_endpoint(extractEndpoint(s))
, m_baseUrl(extractBaseUrl(s, m_service, m_endpoint, m_storageAccount))
, m_baseUrl(extractBaseUrl(m_service, m_endpoint, m_storageAccount))
{
const std::string sasString = extractSasToken(s);
if (!sasString.empty())
Expand Down Expand Up @@ -247,18 +250,9 @@ std::string AZ::Config::extractEndpoint(const std::string s)
return "core.windows.net";
}

std::string AZ::Config::extractBaseUrl(
const std::string s,
const std::string service,
const std::string endpoint,
const std::string account)
{
return account + "." + service + "." + endpoint + "/";
}

std::unique_ptr<std::size_t> AZ::tryGetSize(
const std::string rawPath,
const http::Headers userHeaders,
const http::Headers /*userHeaders*/,
const http::Query query) const
{
Headers headers(m_config->baseHeaders());
Expand Down
1 change: 0 additions & 1 deletion arbiter/drivers/az.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class AZ::Config
private:
static std::string extractService(std::string j);
static std::string extractEndpoint(std::string j);
static std::string extractBaseUrl(std::string j, std::string endpoint, std::string service, std::string account);
static std::string extractStorageAccount(std::string j);
static std::string extractStorageAccessKey(std::string j);
static std::string extractSasToken(std::string j);
Expand Down
12 changes: 7 additions & 5 deletions arbiter/drivers/dropbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,21 @@ bool Dropbox::get(
headers["Dropbox-API-Arg"] = json{{ "path", "/" + path }}.dump();
headers.insert(userHeaders.begin(), userHeaders.end());

const Response res(Http::internalGet(getUrl, headers, query));
Response res(Http::internalGet(getUrl, headers, query));

if (res.ok())
{
if (!userHeaders.count("Range"))
{
if (!res.headers().count("dropbox-api-result"))
Headers headers = res.headers();
if (!headers.count("dropbox-api-result"))
{
std::cout << "No dropbox-api-result header found" << std::endl;
return false;
}

json rx;
try { rx = json::parse(res.headers().at("dropbox-api-result")); }
try { rx = json::parse(headers.at("dropbox-api-result")); }
catch (...) { std::cout << "Failed to parse result" << std::endl; }

if (!rx.is_null())
Expand Down Expand Up @@ -215,9 +216,10 @@ std::vector<char> Dropbox::put(

headers.insert(userHeaders.begin(), userHeaders.end());

const Response res(Http::internalPost(putUrl, data, headers, query));
Response res(Http::internalPost(putUrl, data, headers, query));

if (!res.ok()) throw ArbiterError(res.str());
if (!res.ok())
throw ArbiterError(res.str());
return res.data();
}

Expand Down
2 changes: 1 addition & 1 deletion arbiter/drivers/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void Fs::copy(std::string src, std::string dst) const
outstream << instream.rdbuf();
}

std::vector<std::string> Fs::glob(std::string path, bool verbose) const
std::vector<std::string> Fs::glob(std::string path, bool /*verbose*/) const
{
return arbiter::glob(path);
}
Expand Down
20 changes: 9 additions & 11 deletions arbiter/drivers/google.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ std::unique_ptr<std::size_t> Google::tryGetSize(const std::string path) const
const GResource resource(path);

drivers::Https https(m_pool);
const auto res(
https.internalHead(resource.endpoint(), headers, altMediaQuery));
http::Response res(https.internalHead(resource.endpoint(), headers, altMediaQuery));

if (res.ok())
{
Expand All @@ -132,14 +131,14 @@ bool Google::get(
const std::string path,
std::vector<char>& data,
const http::Headers userHeaders,
const http::Query query) const
const http::Query /*query*/) const
{
http::Headers headers(m_auth->headers());
headers.insert(userHeaders.begin(), userHeaders.end());
const GResource resource(path);

drivers::Https https(m_pool);
const auto res(
http::Response res(
https.internalGet(resource.endpoint(), headers, altMediaQuery));

if (res.ok())
Expand Down Expand Up @@ -173,12 +172,13 @@ std::vector<char> Google::put(
query["name"] = http::sanitize(resource.object(), GResource::exclusions);

drivers::Https https(m_pool);
const auto res(https.internalPost(url, data, headers, query));
if (!res.ok()) throw ArbiterError(res.str());
http::Response res(https.internalPost(url, data, headers, query));
if (!res.ok())
throw ArbiterError(res.str());
return res.data();
}

std::vector<std::string> Google::glob(std::string path, bool verbose) const
std::vector<std::string> Google::glob(std::string path, bool /*verbose*/) const
{
std::vector<std::string> results;

Expand All @@ -203,12 +203,10 @@ std::vector<std::string> Google::glob(std::string path, bool verbose) const
{
if (pageToken.size()) query["pageToken"] = pageToken;

const auto res(https.internalGet(url, m_auth->headers(), query));
http::Response res(https.internalGet(url, m_auth->headers(), query));

if (!res.ok())
{
throw ArbiterError(std::to_string(res.code()) + ": " + res.str());
}

const json j(json::parse(res.str()));
for (const json& item : j.at("items"))
Expand Down Expand Up @@ -309,7 +307,7 @@ void Google::Auth::maybeRefresh() const

http::Pool pool;
drivers::Https https(pool);
const auto res(https.internalPost(tokenRequestUrl, body, headers));
http::Response res(https.internalPost(tokenRequestUrl, body, headers));

if (!res.ok())
{
Expand Down
24 changes: 7 additions & 17 deletions arbiter/drivers/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ Http::Http(
: Driver(driverProtocol, profile)
, m_pool(pool)
, m_httpProtocol(httpProtocol)
{
#ifndef ARBITER_CURL
throw ArbiterError("Cannot create HTTP driver - no curl support was built");
#endif
}
{}

std::unique_ptr<Http> Http::create(Pool& pool)
{
Expand Down Expand Up @@ -150,17 +146,11 @@ bool Http::get(
const Headers headers,
const Query query) const
{
bool good(false);

auto http(m_pool.acquire());
Resource http(m_pool.acquire());
Response res(http.get(typedPath(path), headers, query));


data = res.data();
if (res.ok())
good = true;

return good;
return res.ok();
}

std::vector<char> Http::put(
Expand All @@ -169,8 +159,8 @@ std::vector<char> Http::put(
const Headers headers,
const Query query) const
{
auto http(m_pool.acquire());
auto res(http.put(typedPath(path), data, headers, query));
Resource http(m_pool.acquire());
Response res(http.put(typedPath(path), data, headers, query));

if (!res.ok())
{
Expand All @@ -195,8 +185,8 @@ void Http::post(
const Headers headers,
const Query query) const
{
auto http(m_pool.acquire());
auto res(http.post(typedPath(path), data, headers, query));
Resource http(m_pool.acquire());
Response res(http.post(typedPath(path), data, headers, query));

if (!res.ok())
{
Expand Down
Loading
Loading