Mercurial > hg > orthanc-object-storage
changeset 153:6dd8bb916573
cppcheck
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Jun 2024 14:29:22 +0200 |
parents | d62f52be1943 |
children | e8ac39175eaf |
files | Aws/AwsS3StoragePlugin.cpp Azure/AzureBlobStoragePlugin.cpp Common/BaseStorage.h Common/EncryptionConfigurator.h Common/EncryptionHelpers.h Common/FileSystemStorage.h Common/IStorage.h Google/GoogleStoragePlugin.cpp UnitTestsSources/EncryptionTests.cpp |
diffstat | 9 files changed, 65 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp Fri Jun 21 11:22:57 2024 +0200 +++ b/Aws/AwsS3StoragePlugin.cpp Fri Jun 21 14:29:22 2024 +0200 @@ -66,10 +66,14 @@ virtual ~AwsS3StoragePlugin(); - virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual bool HasFileExists() {return false;}; + virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + + virtual bool HasFileExists() ORTHANC_OVERRIDE + { + return false; + } }; @@ -91,7 +95,7 @@ { } - virtual void Write(const char* data, size_t size) + virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE { Aws::S3::Model::PutObjectRequest putObjectRequest; @@ -139,7 +143,7 @@ } - virtual size_t GetSize() + virtual size_t GetSize() ORTHANC_OVERRIDE { std::string firstExceptionMessage; @@ -161,12 +165,12 @@ throw StoragePluginException(firstExceptionMessage); } - virtual void ReadWhole(char* data, size_t size) + virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE { _Read(data, size, 0, false); } - virtual void ReadRange(char* data, size_t size, size_t fromOffset) + virtual void ReadRange(char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE { _Read(data, size, fromOffset, true); } @@ -283,7 +287,7 @@ { } - virtual void Write(const char* data, size_t size) + virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE { boost::interprocess::bufferstream buffer(const_cast<char*>(static_cast<const char*>(data)), static_cast<size_t>(size)); std::shared_ptr<Aws::IOStream> body = Aws::MakeShared<Aws::IOStream>(ALLOCATION_TAG, buffer.rdbuf()); @@ -315,7 +319,7 @@ } - virtual void ReadWhole(char* data, size_t size) + virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE { std::string firstExceptionMessage; @@ -395,14 +399,14 @@ /** * Gets the currently configured log level for this logger. */ - virtual Aws::Utils::Logging::LogLevel GetLogLevel() const + virtual Aws::Utils::Logging::LogLevel GetLogLevel() const ORTHANC_OVERRIDE { return Aws::Utils::Logging::LogLevel::Trace; } /** * Does a printf style output to the output stream. Don't use this, it's unsafe. See LogStream */ - virtual void Log(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* formatStr, ...) + virtual void Log(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const char* formatStr, ...) ORTHANC_OVERRIDE { Aws::StringStream ss; @@ -445,7 +449,7 @@ /** * Writes the stream to the output stream. */ - virtual void LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream) + virtual void LogStream(Aws::Utils::Logging::LogLevel logLevel, const char* tag, const Aws::OStringStream &messageStream) ORTHANC_OVERRIDE { if (logLevel == Aws::Utils::Logging::LogLevel::Debug || logLevel == Aws::Utils::Logging::LogLevel::Trace) { @@ -464,7 +468,7 @@ /** * Writes any buffered messages to the underlying device if the logger supports buffering. */ - virtual void Flush() {} + virtual void Flush() ORTHANC_OVERRIDE {} }; IStorage* AwsS3StoragePluginFactory::CreateStorage(const std::string& nameForLogs, const OrthancPlugins::OrthancConfiguration& orthancConfig)
--- a/Azure/AzureBlobStoragePlugin.cpp Fri Jun 21 11:22:57 2024 +0200 +++ b/Azure/AzureBlobStoragePlugin.cpp Fri Jun 21 14:29:22 2024 +0200 @@ -47,10 +47,10 @@ bool storageContainsUnknownFiles ); - virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual bool HasFileExists() {return false;}; + virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual bool HasFileExists() ORTHANC_OVERRIDE {return false;}; }; @@ -70,7 +70,7 @@ { } - virtual void Write(const char* data, size_t size) + virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE { try { @@ -123,7 +123,7 @@ { } - virtual size_t GetSize() + virtual size_t GetSize() ORTHANC_OVERRIDE { try { @@ -135,7 +135,7 @@ } } - virtual void ReadWhole(char* data, size_t size) + virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE { try { @@ -148,7 +148,7 @@ } } - virtual void ReadRange(char* data, size_t size, size_t fromOffset) + virtual void ReadRange(char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE { try {
--- a/Common/BaseStorage.h Fri Jun 21 11:22:57 2024 +0200 +++ b/Common/BaseStorage.h Fri Jun 21 14:29:22 2024 +0200 @@ -22,6 +22,9 @@ #pragma once #include "IStorage.h" + +#include <Compatibility.h> + #include <boost/filesystem.hpp> namespace fs = boost::filesystem; @@ -41,7 +44,7 @@ std::string GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled, bool useAlternateExtension = false); public: - virtual void SetRootPath(const std::string& rootPath) + virtual void SetRootPath(const std::string& rootPath) ORTHANC_OVERRIDE { rootPath_ = rootPath; }
--- a/Common/EncryptionConfigurator.h Fri Jun 21 11:22:57 2024 +0200 +++ b/Common/EncryptionConfigurator.h Fri Jun 21 14:29:22 2024 +0200 @@ -22,10 +22,7 @@ #include "EncryptionHelpers.h" -class EncryptionConfigurator +namespace EncryptionConfigurator { - -public: - static EncryptionHelpers* CreateEncryptionHelpers(const OrthancPlugins::OrthancConfiguration& encryptionSection); - -}; + EncryptionHelpers* CreateEncryptionHelpers(const OrthancPlugins::OrthancConfiguration& encryptionSection); +}
--- a/Common/EncryptionHelpers.h Fri Jun 21 11:22:57 2024 +0200 +++ b/Common/EncryptionHelpers.h Fri Jun 21 14:29:22 2024 +0200 @@ -30,7 +30,7 @@ class EncryptionException : public std::runtime_error { public: - EncryptionException(const std::string& what) + explicit EncryptionException(const std::string& what) : std::runtime_error(what) { }
--- a/Common/FileSystemStorage.h Fri Jun 21 11:22:57 2024 +0200 +++ b/Common/FileSystemStorage.h Fri Jun 21 14:29:22 2024 +0200 @@ -41,21 +41,21 @@ {} virtual ~FileSystemWriter() {} - virtual void Write(const char* data, size_t size); + virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE; }; class FileSystemReader: public IStorage::IReader { const fs::path path_; public: - FileSystemReader(const fs::path& path) + explicit FileSystemReader(const fs::path& path) : path_(path) {} virtual ~FileSystemReader() {} - virtual size_t GetSize(); - virtual void ReadWhole(char* data, size_t size); - virtual void ReadRange(char* data, size_t size, size_t fromOffset); + virtual size_t GetSize() ORTHANC_OVERRIDE; + virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE; + virtual void ReadRange(char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE; }; std::string fileSystemRootPath_; @@ -67,12 +67,12 @@ fsync_(fsync) {} - virtual void SetRootPath(const std::string& rootPath) {} + virtual void SetRootPath(const std::string& rootPath) ORTHANC_OVERRIDE {} - virtual IStorage::IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual IStorage::IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); + virtual IStorage::IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual IStorage::IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; - virtual bool HasFileExists() {return true;}; - virtual bool FileExists(const std::string& uuid, OrthancPluginContentType type, bool encryptionEnabled); -}; \ No newline at end of file + virtual bool HasFileExists() ORTHANC_OVERRIDE {return true;}; + virtual bool FileExists(const std::string& uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; +};
--- a/Common/IStorage.h Fri Jun 21 11:22:57 2024 +0200 +++ b/Common/IStorage.h Fri Jun 21 14:29:22 2024 +0200 @@ -27,7 +27,7 @@ class StoragePluginException : public std::runtime_error { public: - StoragePluginException(const std::string& what) + explicit StoragePluginException(const std::string& what) : std::runtime_error(what) { } @@ -44,7 +44,7 @@ // IStorage* CreateStorage(const OrthancPlugins::OrthancConfiguration& orthancConfig); //}; -class IStorage +class IStorage : public boost::noncopyable { public: class IWriter @@ -75,6 +75,10 @@ nameForLogs_(nameForLogs) {} + virtual ~IStorage() + { + } + virtual void SetRootPath(const std::string& rootPath) = 0; virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) = 0;
--- a/Google/GoogleStoragePlugin.cpp Fri Jun 21 11:22:57 2024 +0200 +++ b/Google/GoogleStoragePlugin.cpp Fri Jun 21 14:29:22 2024 +0200 @@ -46,10 +46,10 @@ bool storageContainsUnknownFiles ); - virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); - virtual bool HasFileExists() {return false;}; + virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) ORTHANC_OVERRIDE; + virtual bool HasFileExists() ORTHANC_OVERRIDE {return false;}; }; @@ -71,7 +71,7 @@ { } - virtual void Write(const char* data, size_t size) + virtual void Write(const char* data, size_t size) ORTHANC_OVERRIDE { stream_ = client_.WriteObject(bucketName_, path_); @@ -112,7 +112,7 @@ } - virtual size_t GetSize() + virtual size_t GetSize() ORTHANC_OVERRIDE { std::string firstExceptionMessage; @@ -134,7 +134,7 @@ throw StoragePluginException(firstExceptionMessage); } - void ReadWhole(char* data, size_t size) + virtual void ReadWhole(char* data, size_t size) ORTHANC_OVERRIDE { std::string firstExceptionMessage; @@ -156,7 +156,7 @@ throw StoragePluginException(firstExceptionMessage); } - void ReadRange(char* data, size_t size, size_t fromOffset) + virtual void ReadRange(char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE { std::string firstExceptionMessage; @@ -179,7 +179,7 @@ } private: - virtual void _ReadWhole(const std::string& path, char* data, size_t size) + virtual void _ReadWhole(const std::string& path, char* data, size_t size) ORTHANC_OVERRIDE { auto reader = client_.ReadObject(bucketName_, path); @@ -196,7 +196,7 @@ } } - virtual void _ReadRange(const std::string& path, char* data, size_t size, size_t fromOffset) + virtual void _ReadRange(const std::string& path, char* data, size_t size, size_t fromOffset) ORTHANC_OVERRIDE { auto reader = client_.ReadObject(bucketName_, path, gcs::ReadRange(fromOffset, fromOffset + size)); @@ -213,7 +213,7 @@ } } - size_t _GetSize(const std::string& path) + virtual size_t _GetSize(const std::string& path) ORTHANC_OVERRIDE { auto objectMetadata = client_.GetObjectMetadata(bucketName_, path);
--- a/UnitTestsSources/EncryptionTests.cpp Fri Jun 21 11:22:57 2024 +0200 +++ b/UnitTestsSources/EncryptionTests.cpp Fri Jun 21 14:29:22 2024 +0200 @@ -234,11 +234,12 @@ void MeasurePerformance(size_t sizeInMB, EncryptionHelpers& crypto) { - std::string largePlainText(sizeInMB * 1024 * 1024, 'A'); std::string encryptedMessage; std::string decryptedMessage; { + const std::string largePlainText(sizeInMB * 1024 * 1024, 'A'); + auto start = boost::posix_time::microsec_clock::local_time(); crypto.Encrypt(encryptedMessage, largePlainText);