Commit 9aac9585 authored by Paweł Wegner's avatar Paweł Wegner

Added [ICrypto|IHttp|IHttpServerFactory]::create functions.

parent 12e79570
......@@ -13,8 +13,6 @@
#include "File.h"
#include "GenerateThumbnail.h"
#include "ICloudStorage.h"
#include "Utility/CurlHttp.h"
#include "Utility/MicroHttpdServer.h"
#include "Utility/Utility.h"
using namespace cloudstorage;
......@@ -82,8 +80,8 @@ class DownloadCallback : public IDownloadFileCallback {
CloudContext::CloudContext(QObject* parent)
: QObject(parent),
http_server_factory_(util::make_unique<ServerWrapperFactory>(
util::make_unique<MicroHttpdServerFactory>())),
http_(util::make_unique<curl::CurlHttp>()),
IHttpServerFactory::create())),
http_(IHttp::create()),
thread_pool_(IThreadPool::create(1)) {
util::log_stream(util::make_unique<std::ostream>(&debug_stream_));
std::lock_guard<std::mutex> lock(mutex_);
......
#include "FuseCommon.h"
#include "ICloudStorage.h"
#include "Utility/CurlHttp.h"
#include "Utility/MicroHttpdServer.h"
#include "Utility/Utility.h"
#ifdef WITH_FUSE
......@@ -122,7 +120,7 @@ int fuse_run(fuse_args *args, fuse_cmdline_opts *opts, Json::Value &json) {
auto ctx = new IFileSystem *;
Backend fuse(args, opts->mountpoint, ctx);
fuse_daemonize(opts->foreground);
auto http = std::make_shared<curl::CurlHttp>();
std::shared_ptr<IHttp> http = IHttp::create();
auto temporary_directory = json["temporary_directory"].asString();
if (temporary_directory.empty())
temporary_directory = util::temporary_directory();
......@@ -206,7 +204,7 @@ int fuse_run(int argc, char **argv) {
<< "\n";
}
std::promise<cloudstorage::HttpServerData> result;
auto server = cloudstorage::MicroHttpdServerFactory().create(
auto server = cloudstorage::IHttpServerFactory::create()->create(
std::make_shared<cloudstorage::HttpServerCallback>(result), "",
IHttpServer::Type::Authorization);
auto key = result.get_future().get();
......
......@@ -7,7 +7,6 @@
#include <string>
#include "FuseCommon.h"
#include "IFileSystem.h"
#include "Utility/CurlHttp.h"
#include "Utility/Utility.h"
namespace cloudstorage {
......
......@@ -10,7 +10,6 @@
#include "FuseCommon.h"
#include "IFileSystem.h"
#include "Utility/CurlHttp.h"
#include "Utility/Utility.h"
namespace cloudstorage {
......
......@@ -28,10 +28,7 @@
#include <fstream>
#include <sstream>
#include "Utility/CryptoPP.h"
#include "Utility/CurlHttp.h"
#include "Utility/Item.h"
#include "Utility/MicroHttpdServer.h"
#include "Utility/Utility.h"
#include "Request/CreateDirectoryRequest.h"
......@@ -164,16 +161,15 @@ void CloudProvider::initialize(InitData&& data) {
[this](std::string v) { auth()->set_error_page(v); });
#ifdef WITH_CRYPTOPP
if (!crypto_) crypto_ = util::make_unique<CryptoPP>();
if (!crypto_) crypto_ = ICrypto::create();
#endif
#ifdef WITH_CURL
if (!http_) http_ = util::make_unique<curl::CurlHttp>();
if (!http_) http_ = IHttp::create();
#endif
#ifdef WITH_MICROHTTPD
if (!http_server_)
http_server_ = util::make_unique<MicroHttpdServerFactory>();
if (!http_server_) http_server_ = IHttpServerFactory::create();
#endif
if (!thread_pool_) thread_pool_ = IThreadPool::create(1);
......
......@@ -70,6 +70,8 @@ class ICrypto {
* @return hex string
*/
virtual std::string hex(const std::string& hash) = 0;
static ICrypto::Pointer create();
};
} // namespace cloudstorage
......
......@@ -187,6 +187,8 @@ class IHttp {
virtual IHttpRequest::Pointer create(const std::string& url,
const std::string& method = "GET",
bool follow_redirect = true) const = 0;
static IHttp::Pointer create();
};
} // namespace cloudstorage
......
......@@ -100,6 +100,8 @@ class IHttpServerFactory {
virtual IHttpServer::Pointer create(IHttpServer::ICallback::Pointer,
const std::string& session_id,
IHttpServer::Type) = 0;
static IHttpServerFactory::Pointer create();
};
} // namespace cloudstorage
......
......@@ -29,9 +29,12 @@
#include <cryptopp/hex.h>
#include <cryptopp/hmac.h>
#include <cryptopp/sha.h>
#include "Utility/Utility.h"
namespace cloudstorage {
ICrypto::Pointer ICrypto::create() { return util::make_unique<CryptoPP>(); }
std::string CryptoPP::sha256(const std::string& message) {
::CryptoPP::SHA256 hash;
std::string result;
......@@ -75,4 +78,12 @@ std::string CryptoPP::hex(const std::string& hash) {
} // namespace cloudstorage
#else
#include "ICrypto.h"
namespace cloudstorage {
ICrypto::Pointer ICrypto::create() { return nullptr; }
} // namespace cloudstorage
#endif // WITH_CRYPTOPP
......@@ -37,6 +37,8 @@ const uint32_t POLL_TIMEOUT = 100;
namespace cloudstorage {
IHttp::Pointer IHttp::create() { return util::make_unique<curl::CurlHttp>(); }
namespace curl {
namespace {
......@@ -327,4 +329,12 @@ IHttpRequest::Pointer CurlHttp::create(const std::string& url,
} // namespace cloudstorage
#else
#include "IHttp.h"
namespace cloudstorage {
IHttp::Pointer IHttp::create() { return nullptr; }
} // namespace cloudstorage
#endif // WITH_CURL
......@@ -73,6 +73,10 @@ void http_request_completed(void*, MHD_Connection*, void** con_cls,
} // namespace
IHttpServerFactory::Pointer IHttpServerFactory::create() {
return util::make_unique<MicroHttpdServerFactory>();
}
MicroHttpdServer::Response::Response(MHD_Connection* connection, int code,
const IResponse::Headers& headers,
int size,
......@@ -187,4 +191,12 @@ IHttpServer::Pointer MicroHttpdServerFactory::create(
} // namespace cloudstorage
#else
#include "IHttpServer.h"
namespace cloudstorage {
IHttpServerFactory::Pointer IHttpServerFactory::create() { return nullptr; }
} // namespace cloudstorage
#endif // WITH_MICROHTTPD
......@@ -29,7 +29,6 @@
#include "CloudProvider/LocalDrive.h"
#include "ICloudProvider.h"
#include "ICloudStorage.h"
#include "Utility/CurlHttp.h"
#include "Utility/Utility.h"
using namespace cloudstorage;
......@@ -275,7 +274,7 @@ class CloudProviderTest : public ::testing::Test {
ASSERT_NE(item, nullptr);
auto lnk = p->getItemUrlAsync(item)->result().right();
ASSERT_NE(lnk, nullptr);
auto http = util::make_unique<curl::CurlHttp>();
auto http = IHttp::create();
auto request = http->create(*lnk, "HEAD", true);
std::promise<IHttpRequest::Response> response_promise;
request->send(
......
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