mirror of
https://github.com/minio/minio-cpp.git
synced 2025-07-02 03:22:24 +03:00
Include headers explicitly and add constructors to comply C++20 (#116)
* Added constructors to become C++20 * fixed: implementation details leak in headers
This commit is contained in:
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Declare files that will always have LF line endings on checkout.
|
||||
*.sh test eol=lf
|
@ -13,7 +13,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <fstream>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "args.h"
|
||||
#include "client.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
|
||||
int main() {
|
||||
// Create S3 base URL.
|
||||
|
@ -13,7 +13,17 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <fstream>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "args.h"
|
||||
#include "client.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
|
||||
int main() {
|
||||
// Create S3 base URL.
|
||||
|
@ -16,10 +16,17 @@
|
||||
#ifndef _MINIO_S3_ARGS_H
|
||||
#define _MINIO_S3_ARGS_H
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "signer.h"
|
||||
#include "sse.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
namespace s3 {
|
||||
|
@ -16,11 +16,18 @@
|
||||
#ifndef _MINIO_S3_BASE_CLIENT_H
|
||||
#define _MINIO_S3_BASE_CLIENT_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "args.h"
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
#include "select.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
namespace s3 {
|
||||
|
@ -16,11 +16,13 @@
|
||||
#ifndef _MINIO_S3_CLIENT_H
|
||||
#define _MINIO_S3_CLIENT_H
|
||||
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include "args.h"
|
||||
#include "baseclient.h"
|
||||
#include "config.h"
|
||||
#include "error.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
||||
#ifndef _MINIO_CREDS_CREDENTIALS_H
|
||||
#define _MINIO_CREDS_CREDENTIALS_H
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
@ -34,6 +38,30 @@ struct Credentials {
|
||||
utils::UtcTime expiration = {};
|
||||
|
||||
Credentials() = default;
|
||||
explicit Credentials(error::Error err) : err(std::move(err)) {}
|
||||
|
||||
explicit Credentials(error::Error err, std::string access_key,
|
||||
std::string secret_key)
|
||||
: err(std::move(err)),
|
||||
access_key(std::move(access_key)),
|
||||
secret_key(std::move(secret_key)) {}
|
||||
|
||||
explicit Credentials(error::Error err, std::string access_key,
|
||||
std::string secret_key, std::string session_token)
|
||||
: err(std::move(err)),
|
||||
access_key(std::move(access_key)),
|
||||
secret_key(std::move(secret_key)),
|
||||
session_token(std::move(session_token)) {}
|
||||
|
||||
explicit Credentials(error::Error err, std::string access_key,
|
||||
std::string secret_key, std::string session_token,
|
||||
utils::UtcTime expiration)
|
||||
: err(std::move(err)),
|
||||
access_key(std::move(access_key)),
|
||||
secret_key(std::move(secret_key)),
|
||||
session_token(std::move(session_token)),
|
||||
expiration(std::move(expiration)) {}
|
||||
|
||||
~Credentials() = default;
|
||||
|
||||
bool IsExpired() const { return expired(expiration); }
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace minio {
|
||||
namespace error {
|
||||
@ -32,9 +33,9 @@ class Error {
|
||||
Error(const Error&) = default;
|
||||
Error& operator=(const Error&) = default;
|
||||
|
||||
Error(Error&& v) : msg_(std::move(v.msg_)) {}
|
||||
Error(Error&& v) noexcept : msg_(std::move(v.msg_)) {}
|
||||
|
||||
Error& operator=(Error&& v) {
|
||||
Error& operator=(Error&& v) noexcept {
|
||||
if (this != &v) {
|
||||
msg_ = std::move(v.msg_);
|
||||
}
|
||||
|
@ -16,16 +16,15 @@
|
||||
#ifndef _MINIO_HTTP_H
|
||||
#define _MINIO_HTTP_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Multi.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
@ -65,6 +64,13 @@ struct Url {
|
||||
std::string query_string;
|
||||
|
||||
Url() = default;
|
||||
explicit Url(bool https, std::string host, unsigned int port,
|
||||
std::string path, std::string query_string)
|
||||
: https(https),
|
||||
host(std::move(host)),
|
||||
port(port),
|
||||
path(std::move(path)),
|
||||
query_string(std::move(query_string)) {}
|
||||
~Url() = default;
|
||||
|
||||
explicit operator bool() const { return !host.empty(); }
|
||||
@ -91,6 +97,16 @@ struct DataFunctionArgs {
|
||||
void* userdata = nullptr;
|
||||
|
||||
DataFunctionArgs() = default;
|
||||
explicit DataFunctionArgs(curlpp::Easy* handle, Response* response,
|
||||
void* userdata)
|
||||
: handle(handle), response(response), userdata(userdata) {}
|
||||
explicit DataFunctionArgs(curlpp::Easy* handle, Response* response,
|
||||
std::string datachunk, void* userdata)
|
||||
: handle(handle),
|
||||
response(response),
|
||||
datachunk(std::move(datachunk)),
|
||||
userdata(userdata) {}
|
||||
|
||||
~DataFunctionArgs() = default;
|
||||
}; // struct DataFunctionArgs
|
||||
|
||||
|
@ -16,11 +16,13 @@
|
||||
#ifndef _MINIO_CREDS_PROVIDERS_H
|
||||
#define _MINIO_CREDS_PROVIDERS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "credentials.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
|
||||
#define DEFAULT_DURATION_SECONDS (60 * 60 * 24) // 1 day.
|
||||
@ -34,6 +36,8 @@ struct Jwt {
|
||||
unsigned int expiry = 0;
|
||||
|
||||
Jwt() = default;
|
||||
explicit Jwt(std::string token, unsigned int expiry)
|
||||
: token(std::move(token)), expiry(expiry) {}
|
||||
~Jwt() = default;
|
||||
|
||||
explicit operator bool() const { return !token.empty(); }
|
||||
|
@ -16,9 +16,13 @@
|
||||
#ifndef _MINIO_REQUEST_H
|
||||
#define _MINIO_REQUEST_H
|
||||
|
||||
#include "credentials.h"
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "signer.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
namespace s3 {
|
||||
|
@ -16,9 +16,14 @@
|
||||
#ifndef _MINIO_S3_RESPONSE_H
|
||||
#define _MINIO_S3_RESPONSE_H
|
||||
|
||||
#include <pugixml.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
namespace s3 {
|
||||
|
@ -16,8 +16,11 @@
|
||||
#ifndef _MINIO_S3_SELECT_H
|
||||
#define _MINIO_S3_SELECT_H
|
||||
|
||||
#include <pugixml.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "types.h"
|
||||
|
||||
|
@ -16,9 +16,10 @@
|
||||
#ifndef _MINIO_SIGNER_H
|
||||
#define _MINIO_SIGNER_H
|
||||
|
||||
#include <openssl/hmac.h>
|
||||
#include <string>
|
||||
|
||||
#include "http.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
namespace signer {
|
||||
|
@ -16,6 +16,8 @@
|
||||
#ifndef _MINIO_S3_SSE_H
|
||||
#define _MINIO_S3_SSE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
|
@ -16,10 +16,17 @@
|
||||
#ifndef _MINIO_S3_TYPES_H
|
||||
#define _MINIO_S3_TYPES_H
|
||||
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace minio {
|
||||
@ -310,6 +317,8 @@ struct Bucket {
|
||||
utils::UtcTime creation_date;
|
||||
|
||||
Bucket() = default;
|
||||
explicit Bucket(std::string name, utils::UtcTime creation_date)
|
||||
: name(std::move(name)), creation_date(std::move(creation_date)) {}
|
||||
~Bucket() = default;
|
||||
}; // struct Bucket
|
||||
|
||||
@ -320,6 +329,8 @@ struct Part {
|
||||
size_t size = 0;
|
||||
|
||||
Part() = default;
|
||||
explicit Part(unsigned int number, std::string etag)
|
||||
: number(number), etag(std::move(etag)) {}
|
||||
~Part() = default;
|
||||
}; // struct Part
|
||||
|
||||
|
@ -20,34 +20,23 @@
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <sys/types.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <ios>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "error.h"
|
||||
|
||||
namespace minio {
|
||||
namespace utils {
|
||||
inline constexpr unsigned int kMaxMultipartCount = 10000; // 10000 parts
|
||||
inline constexpr unsigned long long kMaxObjectSize = 5497558138880ULL; // 5TiB
|
||||
inline constexpr unsigned long long kMaxPartSize = 5368709120UL; // 5GiB
|
||||
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB
|
||||
inline constexpr unsigned int kMaxMultipartCount = 10000; // 10000 parts
|
||||
inline constexpr uint64_t kMaxObjectSize = 5'497'558'138'880; // 5TiB
|
||||
inline constexpr uint64_t kMaxPartSize = 5'368'709'120; // 5GiB
|
||||
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB
|
||||
|
||||
// GetEnv copies the environment variable name into var
|
||||
bool GetEnv(std::string& var, const char* name);
|
||||
@ -72,7 +61,7 @@ inline const char* BoolToString(bool b) { return b ? "true" : "false"; }
|
||||
// Trim trims leading and trailing character of a string.
|
||||
std::string Trim(std::string_view str, char ch = ' ');
|
||||
|
||||
// CheckNonemptystring checks whether string is not empty after trimming
|
||||
// CheckNonEmptyString checks whether string is not empty after trimming
|
||||
// whitespaces.
|
||||
bool CheckNonEmptyString(std::string_view str);
|
||||
|
||||
|
19
src/args.cc
19
src/args.cc
@ -15,8 +15,21 @@
|
||||
|
||||
#include "args.h"
|
||||
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "signer.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
minio::error::Error minio::s3::BucketArgs::Validate() const {
|
||||
return utils::CheckBucketName(bucket);
|
||||
@ -346,7 +359,7 @@ minio::error::Error minio::s3::ComposeSource::BuildHeaders(
|
||||
size_t minio::s3::ComposeSource::ObjectSize() const {
|
||||
if (object_size_ == -1) {
|
||||
std::cerr << "ABORT: ComposeSource::BuildHeaders() must be called prior to "
|
||||
"this method invocation. This shoud not happen."
|
||||
"this method invocation. This should not happen."
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
@ -357,7 +370,7 @@ size_t minio::s3::ComposeSource::ObjectSize() const {
|
||||
minio::utils::Multimap minio::s3::ComposeSource::Headers() const {
|
||||
if (!headers_) {
|
||||
std::cerr << "ABORT: ComposeSource::BuildHeaders() must be called prior to "
|
||||
"this method invocation. This shoud not happen."
|
||||
"this method invocation. This should not happen."
|
||||
<< std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
@ -441,7 +454,7 @@ minio::error::Error minio::s3::ListenBucketNotificationArgs::Validate() const {
|
||||
return err;
|
||||
}
|
||||
if (func == nullptr) {
|
||||
error::Error("notification records function must be set");
|
||||
return error::Error("notification records function must be set");
|
||||
}
|
||||
return error::SUCCESS;
|
||||
}
|
||||
|
@ -15,6 +15,32 @@
|
||||
|
||||
#include "baseclient.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <ostream>
|
||||
#include <pugixml.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "args.h"
|
||||
#include "config.h"
|
||||
#include "credentials.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
#include "select.h"
|
||||
#include "signer.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
minio::utils::Multimap minio::s3::GetCommonListObjectsQueryParams(
|
||||
const std::string& delimiter, const std::string& encoding_type,
|
||||
unsigned int max_keys, const std::string& prefix) {
|
||||
@ -955,7 +981,7 @@ minio::s3::BaseClient::GetPresignedPostFormData(PostPolicy policy) {
|
||||
|
||||
if (provider_ == nullptr) {
|
||||
return error::Error(
|
||||
"Anonymous access does not require presigned post form-data");
|
||||
"Anonymous access does not require pre-signed post form-data");
|
||||
}
|
||||
|
||||
std::string region;
|
||||
|
@ -15,6 +15,26 @@
|
||||
|
||||
#include "client.h"
|
||||
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <type_traits>
|
||||
|
||||
#include "args.h"
|
||||
#include "baseclient.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
#include "sse.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
minio::s3::ListObjectsResult::ListObjectsResult(error::Error err)
|
||||
: failed_(true) {
|
||||
this->resp_.contents.push_back(Item(std::move(err)));
|
||||
@ -284,7 +304,7 @@ minio::s3::ComposeObjectResponse minio::s3::Client::ComposeObject(
|
||||
upc_args.part_number = part_number;
|
||||
UploadPartCopyResponse resp = UploadPartCopy(upc_args);
|
||||
if (!resp) return resp;
|
||||
parts.push_back(Part{part_number, resp.etag});
|
||||
parts.push_back(Part(part_number, std::move(resp.etag)));
|
||||
} else {
|
||||
while (size > 0) {
|
||||
part_number++;
|
||||
@ -306,10 +326,11 @@ minio::s3::ComposeObjectResponse minio::s3::Client::ComposeObject(
|
||||
upc_args.headers = headerscopy;
|
||||
upc_args.upload_id = upload_id;
|
||||
upc_args.part_number = part_number;
|
||||
UploadPartCopyResponse resp = UploadPartCopy(upc_args);
|
||||
if (!resp) return resp;
|
||||
parts.push_back(Part{part_number, resp.etag});
|
||||
|
||||
{
|
||||
UploadPartCopyResponse resp = UploadPartCopy(upc_args);
|
||||
if (!resp) return resp;
|
||||
parts.push_back(Part(part_number, std::move(resp.etag)));
|
||||
}
|
||||
offset = start_bytes;
|
||||
size -= (end_bytes - start_bytes);
|
||||
}
|
||||
@ -475,7 +496,7 @@ minio::s3::PutObjectResponse minio::s3::Client::PutObject(
|
||||
actual_args.userdata = args.progress_userdata;
|
||||
args.progressfunc(actual_args);
|
||||
}
|
||||
parts.push_back(Part{part_number, resp.etag});
|
||||
parts.push_back(Part(part_number, std::move(resp.etag)));
|
||||
} else {
|
||||
return resp;
|
||||
}
|
||||
|
@ -16,6 +16,11 @@
|
||||
#include "credentials.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "utils.h"
|
||||
|
||||
bool minio::creds::expired(const utils::UtcTime& expiration) {
|
||||
if (!expiration) return false;
|
||||
@ -44,6 +49,7 @@ minio::creds::Credentials minio::creds::Credentials::ParseXML(
|
||||
text = credentials.node().select_node("Expiration/text()");
|
||||
auto expiration = utils::UtcTime::FromISO8601UTC(text.node().value());
|
||||
|
||||
return Credentials{error::SUCCESS, access_key, secret_key, session_token,
|
||||
expiration};
|
||||
return Credentials(error::SUCCESS, std::move(access_key),
|
||||
std::move(secret_key), std::move(session_token),
|
||||
expiration);
|
||||
}
|
||||
|
44
src/http.cc
44
src/http.cc
@ -13,9 +13,37 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "http.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <curlpp/Easy.hpp>
|
||||
#include <curlpp/Exception.hpp>
|
||||
#include <curlpp/Infos.hpp>
|
||||
#include <curlpp/Multi.hpp>
|
||||
#include <curlpp/Options.hpp>
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <ws2def.h> // NOTE needed for AF_INET6
|
||||
#include <ws2ipdef.h> // NOTE needed for sockaddr_in6
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "utils.h"
|
||||
|
||||
std::string minio::http::Url::String() const {
|
||||
if (host.empty()) return {};
|
||||
@ -105,7 +133,8 @@ minio::http::Url minio::http::Url::Parse(std::string value) {
|
||||
if (!https && port == 80) port = 0;
|
||||
if (https && port == 443) port = 0;
|
||||
|
||||
return Url{https, host, port, path, query_string};
|
||||
return Url(https, std::move(host), port, std::move(path),
|
||||
std::move(query_string));
|
||||
}
|
||||
|
||||
minio::error::Error minio::http::Response::ReadStatusCode() {
|
||||
@ -248,7 +277,8 @@ size_t minio::http::Response::ResponseCallback(curlpp::Multi* const requests,
|
||||
|
||||
// If data function is set and the request is successful, send data.
|
||||
if (datafunc != nullptr && status_code >= 200 && status_code <= 299) {
|
||||
DataFunctionArgs args{request, this, response_, userdata};
|
||||
DataFunctionArgs args(request, this, std::string(this->response_),
|
||||
userdata);
|
||||
if (!datafunc(args)) requests->remove(request);
|
||||
} else {
|
||||
body = response_;
|
||||
@ -259,7 +289,7 @@ size_t minio::http::Response::ResponseCallback(curlpp::Multi* const requests,
|
||||
|
||||
// If data function is set and the request is successful, send data.
|
||||
if (datafunc != nullptr && status_code >= 200 && status_code <= 299) {
|
||||
DataFunctionArgs args{request, this, std::string(buffer, length), userdata};
|
||||
DataFunctionArgs args(request, this, std::string(buffer, length), userdata);
|
||||
if (!datafunc(args)) requests->remove(request);
|
||||
} else {
|
||||
body.append(buffer, length);
|
||||
@ -368,9 +398,9 @@ minio::http::Response minio::http::Request::execute() {
|
||||
while (!requests.perform(&left)) {
|
||||
}
|
||||
while (left) {
|
||||
fd_set fdread;
|
||||
fd_set fdwrite;
|
||||
fd_set fdexcep;
|
||||
fd_set fdread{};
|
||||
fd_set fdwrite{};
|
||||
fd_set fdexcep{};
|
||||
int maxfd = 0;
|
||||
|
||||
FD_ZERO(&fdread);
|
||||
|
@ -17,22 +17,32 @@
|
||||
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "providers.h"
|
||||
|
||||
#include <INIReader.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "signer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <ws2def.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "credentials.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "signer.h"
|
||||
#include "utils.h"
|
||||
|
||||
minio::error::Error minio::creds::checkLoopbackHost(const std::string& host) {
|
||||
struct addrinfo hints = {};
|
||||
hints.ai_family = AF_INET;
|
||||
@ -82,8 +92,8 @@ minio::creds::Credentials minio::creds::ChainedProvider::Fetch() {
|
||||
minio::creds::StaticProvider::StaticProvider(std::string access_key,
|
||||
std::string secret_key,
|
||||
std::string session_token) {
|
||||
this->creds_ = Credentials{error::SUCCESS, std::move(access_key),
|
||||
std::move(secret_key), std::move(session_token)};
|
||||
this->creds_ = Credentials(error::SUCCESS, std::move(access_key),
|
||||
std::move(secret_key), std::move(session_token));
|
||||
}
|
||||
|
||||
minio::creds::StaticProvider::~StaticProvider() {}
|
||||
@ -105,8 +115,8 @@ minio::creds::EnvAwsProvider::EnvAwsProvider() {
|
||||
}
|
||||
utils::GetEnv(session_token, "AWS_SESSION_TOKEN");
|
||||
|
||||
this->creds_ =
|
||||
Credentials{error::SUCCESS, access_key, secret_key, session_token};
|
||||
this->creds_ = Credentials(error::SUCCESS, std::move(access_key),
|
||||
std::move(secret_key), std::move(session_token));
|
||||
}
|
||||
|
||||
minio::creds::EnvAwsProvider::~EnvAwsProvider() {}
|
||||
@ -121,7 +131,8 @@ minio::creds::EnvMinioProvider::EnvMinioProvider() {
|
||||
|
||||
utils::GetEnv(access_key, "MINIO_ACCESS_KEY");
|
||||
utils::GetEnv(secret_key, "MINIO_SECRET_KEY");
|
||||
this->creds_ = Credentials{error::SUCCESS, access_key, secret_key};
|
||||
this->creds_ =
|
||||
Credentials(error::SUCCESS, std::move(access_key), std::move(secret_key));
|
||||
}
|
||||
|
||||
minio::creds::EnvMinioProvider::~EnvMinioProvider() {}
|
||||
@ -379,7 +390,7 @@ minio::creds::Credentials minio::creds::IamAwsProvider::Fetch() {
|
||||
std::ifstream ifs(token_file);
|
||||
nlohmann::json json = nlohmann::json::parse(ifs);
|
||||
ifs.close();
|
||||
return Jwt{json["access_token"], json["expires_in"]};
|
||||
return Jwt(std::move(json["access_token"]), json["expires_in"]);
|
||||
},
|
||||
url, 0, "", role_arn_, role_session_name_);
|
||||
creds_ = provider.Fetch();
|
||||
|
@ -15,6 +15,23 @@
|
||||
|
||||
#include "request.h"
|
||||
|
||||
#include <exception>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "credentials.h"
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "signer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define EMPTY_SHA256 \
|
||||
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
|
||||
@ -199,7 +216,8 @@ minio::error::Error minio::s3::BaseUrl::BuildUrl(
|
||||
return error::Error("empty bucket name for object name " + object_name);
|
||||
}
|
||||
|
||||
url = http::Url{https, host, port, "/", query_params.ToQueryString()};
|
||||
url = http::Url(https, std::string(this->host), port, "/",
|
||||
query_params.ToQueryString());
|
||||
|
||||
if (bucket_name.empty()) {
|
||||
this->BuildListBucketsUrl(url, region);
|
||||
|
@ -15,6 +15,18 @@
|
||||
|
||||
#include "response.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <pugixml.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "error.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
minio::s3::Response::Response() {}
|
||||
|
||||
minio::s3::Response::~Response() {}
|
||||
@ -90,7 +102,7 @@ minio::s3::ListBucketsResponse minio::s3::ListBucketsResponse::ParseXML(
|
||||
creation_date = utils::UtcTime::FromISO8601UTC(value.c_str());
|
||||
}
|
||||
|
||||
buckets.push_back(Bucket{name, creation_date});
|
||||
buckets.push_back(Bucket(std::move(name), std::move(creation_date)));
|
||||
}
|
||||
|
||||
return buckets;
|
||||
|
@ -15,6 +15,15 @@
|
||||
|
||||
#include "select.h"
|
||||
|
||||
#include <map>
|
||||
#include <pugixml.hpp>
|
||||
#include <string>
|
||||
|
||||
#include "error.h"
|
||||
#include "http.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
void minio::s3::SelectHandler::Reset() {
|
||||
prelude_.clear();
|
||||
prelude_read_ = false;
|
||||
|
@ -15,6 +15,17 @@
|
||||
|
||||
#include "signer.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "http.h"
|
||||
#include "utils.h"
|
||||
|
||||
const char* SIGN_V4_ALGORITHM = "AWS4-HMAC-SHA256";
|
||||
|
||||
std::string minio::signer::GetScope(const utils::UtcTime& time,
|
||||
|
@ -15,6 +15,10 @@
|
||||
|
||||
#include "sse.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
minio::s3::Sse::Sse() {}
|
||||
|
||||
minio::s3::Sse::~Sse() {}
|
||||
|
10
src/types.cc
10
src/types.cc
@ -15,6 +15,16 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include <exception>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "error.h"
|
||||
|
||||
minio::s3::RetentionMode minio::s3::StringToRetentionMode(
|
||||
std::string_view str) noexcept {
|
||||
if (str == "GOVERNANCE") return RetentionMode::kGovernance;
|
||||
|
41
src/utils.cc
41
src/utils.cc
@ -15,11 +15,44 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <corecrt.h>
|
||||
#endif
|
||||
|
||||
#include "utils.h"
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/types.h>
|
||||
#include <zconf.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <clocale>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <curlpp/cURLpp.hpp>
|
||||
#include <exception>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <locale>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "error.h"
|
||||
#include "utils.h"
|
||||
|
||||
const std::string WEEK_DAYS[] = {"Sun", "Mon", "Tue", "Wed",
|
||||
"Thu", "Fri", "Sat"};
|
||||
@ -370,7 +403,7 @@ minio::utils::UtcTime minio::utils::UtcTime::FromISO8601UTC(const char* value) {
|
||||
std::time_t secs = std::mktime(&t);
|
||||
|
||||
unsigned long ul = 0;
|
||||
sscanf(rv, ".%lu", &ul);
|
||||
static_cast<void>(sscanf(rv, ".%lu", &ul));
|
||||
long usecs = (long)ul;
|
||||
|
||||
return UtcTime(secs, usecs);
|
||||
@ -563,7 +596,7 @@ minio::error::Error minio::utils::CalcPartInfo(long object_size,
|
||||
}
|
||||
|
||||
if (object_size >= 0) {
|
||||
if (static_cast<unsigned long long>(object_size) > kMaxObjectSize) {
|
||||
if (static_cast<uint64_t>(object_size) > kMaxObjectSize) {
|
||||
return error::Error("object size " + std::to_string(object_size) +
|
||||
" is not supported; maximum allowed 5TiB");
|
||||
}
|
||||
|
@ -12,11 +12,33 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
#include <thread>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iosfwd>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <ostream>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
#include "args.h"
|
||||
#include "client.h"
|
||||
#include "http.h"
|
||||
#include "providers.h"
|
||||
#include "request.h"
|
||||
#include "response.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
thread_local static std::mt19937 rg{std::random_device{}()};
|
||||
|
||||
@ -534,7 +556,9 @@ class Tests {
|
||||
args.bucket = bucket_name_;
|
||||
args.object = object_name;
|
||||
minio::s3::PutObjectResponse resp = client_.PutObject(args);
|
||||
if (!resp) std::runtime_error("PutObject(): " + resp.Error().String());
|
||||
if (!resp) {
|
||||
throw std::runtime_error("PutObject(): " + resp.Error().String());
|
||||
}
|
||||
object_names.push_back(object_name);
|
||||
}
|
||||
RemoveObjects(object_names);
|
||||
|
Reference in New Issue
Block a user