Skip to content
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

Include headers explicitly and add constructors to comply C++20 #116

Merged
merged 8 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions examples/PutObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fstream>
balamurugana marked this conversation as resolved.
Show resolved Hide resolved
#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.
Expand Down
10 changes: 10 additions & 0 deletions examples/PutObjectProgress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion include/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion include/baseclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 26 additions & 0 deletions include/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,6 +38,28 @@ struct Credentials {
utils::UtcTime expiration = {};

Credentials() = default;
Credentials(error::Error err) : err(err) {}

HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
Credentials(error::Error err, std::string access_key, std::string secret_key)
: err(err),
access_key(std::move(access_key)),
secret_key(std::move(secret_key)) {}

Credentials(error::Error err, std::string access_key, std::string secret_key,
std::string session_token)
: err(err),
access_key(std::move(access_key)),
secret_key(std::move(secret_key)),
session_token(std::move(session_token)) {}

Credentials(error::Error err, std::string access_key, std::string secret_key,
std::string session_token, utils::UtcTime expiration)
: err(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); }
Expand Down
5 changes: 3 additions & 2 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <ostream>
#include <string>
#include <type_traits>

namespace minio {
namespace error {
Expand All @@ -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_)) {}
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved

Error& operator=(Error&& v) {
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
Error& operator=(Error&& v) noexcept {
if (this != &v) {
msg_ = std::move(v.msg_);
}
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
29 changes: 22 additions & 7 deletions include/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -65,6 +64,13 @@ struct Url {
std::string query_string;

Url() = default;
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(); }
Expand All @@ -91,6 +97,15 @@ struct DataFunctionArgs {
void* userdata = nullptr;

DataFunctionArgs() = default;
DataFunctionArgs(curlpp::Easy* handle, Response* response, void* userdata)
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
: handle(handle), response(response), userdata(userdata) {}
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

Expand Down
8 changes: 6 additions & 2 deletions include/providers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -34,6 +36,8 @@ struct Jwt {
unsigned int expiry = 0;

Jwt() = default;
Jwt(std::string token, unsigned int expiry)
: token(std::move(token)), expiry(expiry) {}
~Jwt() = default;

explicit operator bool() const { return !token.empty(); }
Expand Down
8 changes: 6 additions & 2 deletions include/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion include/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion include/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion include/signer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#ifndef _MINIO_SIGNER_H
#define _MINIO_SIGNER_H

#include <openssl/hmac.h>
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
#include <string>

#include "http.h"
#include "utils.h"

namespace minio {
namespace signer {
Expand Down
2 changes: 2 additions & 0 deletions include/sse.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef _MINIO_S3_SSE_H
#define _MINIO_S3_SSE_H

#include <string>

#include "utils.h"

namespace minio {
Expand Down
13 changes: 12 additions & 1 deletion include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -310,6 +317,8 @@ struct Bucket {
utils::UtcTime creation_date;

Bucket() = default;
Bucket(std::string name, utils::UtcTime creation_date)
: name(std::move(name)), creation_date(std::move(creation_date)) {}
~Bucket() = default;
}; // struct Bucket

Expand All @@ -320,6 +329,8 @@ struct Part {
size_t size = 0;

Part() = default;
Part(unsigned int number, std::string etag)
: number(number), etag(std::move(etag)) {}
~Part() = default;
}; // struct Part

Expand Down
31 changes: 11 additions & 20 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,29 @@
#ifndef _MINIO_UTILS_H
#define _MINIO_UTILS_H

#ifndef _WIN32
#ifdef _WIN32
#include <corecrt.h>
#else
#include <pwd.h>
#endif
HJLebbink marked this conversation as resolved.
Show resolved Hide resolved

#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 long long kMaxObjectSize = 5'497'558'138'880; // 5TiB
inline constexpr unsigned long long kMaxPartSize = 5'368'709'120; // 5GiB
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB

HJLebbink marked this conversation as resolved.
Show resolved Hide resolved
// GetEnv copies the environment variable name into var
bool GetEnv(std::string& var, const char* name);
Expand All @@ -72,7 +63,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);

Expand Down
Loading
Loading