annotate Common/StoragePlugin.cpp @ 77:80792bb9600e

new HybridMode
author Alain Mazy <am@osimis.io>
date Fri, 14 Oct 2022 10:36:02 +0200
parents ba1be668e475
children d7295e8678d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
1 /**
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
2 * Cloud storage plugins for Orthanc
37
f55b2afdf53d upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 35
diff changeset
3 * Copyright (C) 2020-2021 Osimis S.A., Belgium
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
4 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
6 * modify it under the terms of the GNU Affero General Public License
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
7 * as published by the Free Software Foundation, either version 3 of
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
8 * the License, or (at your option) any later version.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
9 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
13 * Affero General Public License for more details.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
14 *
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
15 * You should have received a copy of the GNU Affero General Public License
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
17 **/
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
18
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
19
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
20 #if GOOGLE_STORAGE_PLUGIN==1
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
21 # include "../Google/GoogleStoragePlugin.h"
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
22 # define StoragePluginFactory GoogleStoragePluginFactory
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23 #elif AZURE_STORAGE_PLUGIN==1
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
24 # include "../Azure/AzureBlobStoragePlugin.h"
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
25 # define StoragePluginFactory AzureBlobStoragePluginFactory
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
26 #elif AWS_STORAGE_PLUGIN==1
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
27 # include "../Aws/AwsS3StoragePlugin.h"
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
28 # define StoragePluginFactory AwsS3StoragePluginFactory
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29 #else
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 43
diff changeset
30 # pragma message(error "define a plugin")
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
31 #endif
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
33 #include <string.h>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
34 #include <stdio.h>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
35 #include <string>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
36
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
37 #include <iostream>
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
38 #include <boost/filesystem.hpp>
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
39 #include <boost/filesystem/fstream.hpp>
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
40
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
41 #include "../Common/EncryptionHelpers.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
42 #include "../Common/EncryptionConfigurator.h"
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
43 #include "../Common/FileSystemStoragePlugin.h"
35
8a7a5defd5d0 upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
44
8a7a5defd5d0 upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
45 #include <Logging.h>
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
46 #include <SystemToolbox.h>
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
47
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
48 static std::unique_ptr<IStoragePlugin> primaryPlugin;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
49 static std::unique_ptr<IStoragePlugin> secondaryPlugin;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
51 static std::unique_ptr<EncryptionHelpers> crypto;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
52 static bool cryptoEnabled = false;
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
53 static std::string fileSystemRootPath;
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
54 static std::string objectsRootPath;
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
55 static std::string hybridModeNameForLogs = "";
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
56
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
57 typedef enum
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
58 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
59 HybridMode_WriteToFileSystem, // write to disk, try to read first from disk and then, from object-storage
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
60 HybridMode_WriteToObjectStorage, // write to object storage, try to read first from object storage and then, from disk
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
61 HybridMode_Disabled // read and write only from/to object-storage
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
62 } HybridMode;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
63
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
64 static HybridMode hybridMode = HybridMode_Disabled;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
65
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
66 static bool IsReadFromDisk()
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
67 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
68 return hybridMode != HybridMode_Disabled;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
69 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
70
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
71 static bool IsHybridModeEnabled()
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
72 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
73 return hybridMode != HybridMode_Disabled;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
74 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
75
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
76 typedef void LogErrorFunction(const std::string& message);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
77
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
80 static OrthancPluginErrorCode StorageCreate(const char* uuid,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
81 const void* content,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 int64_t size,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83 OrthancPluginContentType type)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
86 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
87 OrthancPlugins::LogInfo(primaryPlugin->GetNameForLogs() + ": creating attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
88 std::unique_ptr<IStoragePlugin::IWriter> writer(primaryPlugin->GetWriterForObject(uuid, type, cryptoEnabled));
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
89
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
90 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
91 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
92 std::string encryptedFile;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
93
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
94 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
95 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
96 crypto->Encrypt(encryptedFile, (const char*)content, size);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
97 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
98 catch (EncryptionException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
99 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
100 OrthancPlugins::LogError(primaryPlugin->GetNameForLogs() + ": error while encrypting object " + std::string(uuid) + ": " + ex.what());
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
101 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
102 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
103
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
104 writer->Write(encryptedFile.data(), encryptedFile.size());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
105 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
106 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
107 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
108 writer->Write(reinterpret_cast<const char*>(content), size);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
109 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
110 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
111 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
112 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
113 OrthancPlugins::LogError(primaryPlugin->GetNameForLogs() + ": error while creating object " + std::string(uuid) + ": " + ex.what());
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
114 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
115 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
116
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
117 return OrthancPluginErrorCode_Success;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
118 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
119
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
120
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
121 static OrthancPluginErrorCode StorageReadRange(IStoragePlugin* plugin,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
122 LogErrorFunction logErrorFunction,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
123 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer.
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
124 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
125 OrthancPluginContentType type,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
126 uint64_t rangeStart)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
127 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
128 assert(!cryptoEnabled);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
129
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
130 try
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
131 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
132 OrthancPlugins::LogInfo(plugin->GetNameForLogs() + ": reading range of attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
133
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
134 std::unique_ptr<IStoragePlugin::IReader> reader(plugin->GetReaderForObject(uuid, type, cryptoEnabled));
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
135 reader->ReadRange(reinterpret_cast<char*>(target->data), target->size, rangeStart);
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
136
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
137 return OrthancPluginErrorCode_Success;
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
138 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
139 catch (StoragePluginException& ex)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
140 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
141 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(ex.what()));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
142 return OrthancPluginErrorCode_StorageAreaPlugin;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
143 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
144 }
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
145
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
146 static OrthancPluginErrorCode StorageReadRange(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the range. The memory buffer is allocated and freed by Orthanc. The length of the range of interest corresponds to the size of this buffer.
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
147 const char* uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
148 OrthancPluginContentType type,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
149 uint64_t rangeStart)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
150 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
151 OrthancPluginErrorCode res = StorageReadRange(primaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
152 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
153 target,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
154 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
155 type,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
156 rangeStart);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
157
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
158 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled())
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
159 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
160 res = StorageReadRange(secondaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
161 OrthancPlugins::LogError, // log errors as errors on second try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
162 target,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
163 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
164 type,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
165 rangeStart);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
166 }
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
167 return res;
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
168 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
169
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
170
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
171
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
172 static OrthancPluginErrorCode StorageReadWhole(IStoragePlugin* plugin,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
173 LogErrorFunction logErrorFunction,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
174 OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it.
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
175 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
176 OrthancPluginContentType type)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
177 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
178 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
179 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
180 OrthancPlugins::LogInfo(plugin->GetNameForLogs() + ": reading whole attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
181 std::unique_ptr<IStoragePlugin::IReader> reader(plugin->GetReaderForObject(uuid, type, cryptoEnabled));
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
182
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
183 size_t fileSize = reader->GetSize();
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
184 size_t size;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
185
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
186 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
187 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
188 size = fileSize - crypto->OVERHEAD_SIZE;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
189 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
190 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
191 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
192 size = fileSize;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
193 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
194
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
195 if (size <= 0)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
196 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
197 logErrorFunction(plugin->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", size of file is too small: " + boost::lexical_cast<std::string>(fileSize) + " bytes");
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
198 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
199 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
200
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
201 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, size) != OrthancPluginErrorCode_Success)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
202 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
203 logErrorFunction(plugin->GetNameForLogs() + ": error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(size) + " bytes");
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
204 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
205 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
206
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
207 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
208 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
209 std::vector<char> encrypted(fileSize);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
210 reader->ReadWhole(encrypted.data(), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
211
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
212 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
213 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
214 crypto->Decrypt(reinterpret_cast<char*>(target->data), encrypted.data(), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
215 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
216 catch (EncryptionException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
217 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
218 logErrorFunction(plugin->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what());
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
219 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
220 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
221 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
222 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
223 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
224 reader->ReadWhole(reinterpret_cast<char*>(target->data), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
225 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
226 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
227 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
228 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
229 logErrorFunction(plugin->GetNameForLogs() + ": error while decrypting object " + std::string(uuid) + ": " + ex.what());
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
230 return OrthancPluginErrorCode_StorageAreaPlugin;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
231 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
232
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
233 return OrthancPluginErrorCode_Success;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
234 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
235
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
236 static OrthancPluginErrorCode StorageReadWhole(OrthancPluginMemoryBuffer64* target, // Memory buffer where to store the content of the file. It must be allocated by the plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it.
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
237 const char* uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
238 OrthancPluginContentType type)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
239 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
240 OrthancPluginErrorCode res = StorageReadWhole(primaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
241 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
242 target,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
243 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
244 type);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
245
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
246 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled())
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
247 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
248 res = StorageReadWhole(secondaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
249 OrthancPlugins::LogError, // log errors as errors on second try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
250 target,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
251 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
252 type);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
253 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
254 return res;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
255 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
256
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
257 static OrthancPluginErrorCode StorageReadWholeLegacy(void** content,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
258 int64_t* size,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
259 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
260 OrthancPluginContentType type)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
261 {
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
262 OrthancPluginMemoryBuffer64 buffer;
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
263 OrthancPluginErrorCode result = StorageReadWhole(&buffer, uuid, type); // will allocate OrthancPluginMemoryBuffer64
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
264
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
265 if (result == OrthancPluginErrorCode_Success)
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
266 {
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
267 *size = buffer.size;
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
268 *content = buffer.data; // orthanc will free the buffer (we don't have to delete it ourselves)
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
269 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
270
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
271 return result;
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
272 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
273
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
274
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
275 // static bool StorageRemoveFromDisk(const char* uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
276 // OrthancPluginContentType type)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
277 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
278 // try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
279 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
280 // namespace fs = boost::filesystem;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
281 // bool fileExisted = false;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
282 // fs::path path = BaseStoragePlugin::GetOrthancFileSystemPath(uuid, fileSystemRootPath);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
283
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
284 // try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
285 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
286 // fs::remove(path);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
287 // fileExisted = true;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
288 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
289 // catch (...)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
290 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
291 // // Ignore the error
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
292 // fileExisted = false;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
293 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
294
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
295 // // Remove the two parent directories, ignoring the error code if
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
296 // // these directories are not empty
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
297
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
298 // try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
299 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
300 // boost::system::error_code err;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
301 // fs::remove(path.parent_path(), err);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
302 // fs::remove(path.parent_path().parent_path(), err);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
303 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
304 // catch (...)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
305 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
306 // // Ignore the error
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
307 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
308
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
309 // return fileExisted;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
310 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
311 // catch(Orthanc::OrthancException& e)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
312 // {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
313 // OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(e.What()));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
314 // return false;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
315 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
316
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
317 // }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
318
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
319
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
320 static OrthancPluginErrorCode StorageRemove(IStoragePlugin* plugin,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
321 LogErrorFunction logErrorFunction,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
322 const char* uuid,
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
323 OrthancPluginContentType type)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
324 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
325 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
326 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
327 OrthancPlugins::LogInfo(plugin->GetNameForLogs() + ": deleting attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
328 plugin->DeleteObject(uuid, type, cryptoEnabled);
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
329 if ((plugin == primaryPlugin.get()) && IsHybridModeEnabled())
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
330 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
331 // not 100% sure the file has been deleted, try the secondary plugin
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
332 return OrthancPluginErrorCode_StorageAreaPlugin;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
333 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
334
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
335 return OrthancPluginErrorCode_Success;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
336 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
337 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
338 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
339 logErrorFunction(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(ex.what()));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
340 return OrthancPluginErrorCode_StorageAreaPlugin;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
341 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
342 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
343
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
344 static OrthancPluginErrorCode StorageRemove(const char* uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
345 OrthancPluginContentType type)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
346 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
347 OrthancPluginErrorCode res = StorageRemove(primaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
348 (IsHybridModeEnabled() ? OrthancPlugins::LogWarning : OrthancPlugins::LogError), // log errors as warning on first try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
349 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
350 type);
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
351
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
352 if (res != OrthancPluginErrorCode_Success && IsHybridModeEnabled())
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
353 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
354 res = StorageRemove(secondaryPlugin.get(),
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
355 OrthancPlugins::LogError, // log errors as errors on second try
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
356 uuid,
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
357 type);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
358 }
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
359 return res;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
360 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
361
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
362
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
363 extern "C"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
364 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
365 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
366 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
367 OrthancPlugins::SetGlobalContext(context);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
368
57
ba1be668e475 fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
369 Orthanc::InitializeFramework("", false);
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
370 Orthanc::Logging::InitializePluginContext(context);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
371
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
372 OrthancPlugins::OrthancConfiguration orthancConfig;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
373
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
374 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is initializing");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
375
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
376 /* Check the version of the Orthanc core */
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
377 if (OrthancPluginCheckVersion(context) == 0)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
378 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
379 char info[1024];
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
380 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
381 context->orthancVersion,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
382 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
383 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
384 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
385 OrthancPlugins::LogError(info);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
386 return -1;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
387 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
388
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
389 try
8
987cb95c1aee Prevent Orthanc to start if plugin fails to start
Alain Mazy
parents: 1
diff changeset
390 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
391 const char* pluginSectionName = StoragePluginFactory::GetConfigurationSectionName();
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
392 static const char* const ENCRYPTION_SECTION = "StorageEncryption";
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
393
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
394 if (orthancConfig.IsSection(pluginSectionName))
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
395 {
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
396 OrthancPlugins::OrthancConfiguration pluginSection;
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
397 orthancConfig.GetSection(pluginSection, pluginSectionName);
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
398
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
399 bool migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
400 std::string hybridModeString = pluginSection.GetStringValue("HybridMode", "Disabled");
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
401
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
402 if (migrationFromFileSystemEnabled && hybridModeString == "Disabled")
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
403 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
404 hybridMode = HybridMode_WriteToObjectStorage;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
405 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 'MigrationFromFileSystemEnabled' configuration is deprecated, use 'HybridMode': 'WriteToObjectStorage' instead");
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
406 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
407 else if (hybridModeString == "WriteToObjectStorage")
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
408 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
409 hybridMode = HybridMode_WriteToObjectStorage;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
410 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToObjectStorage HybridMode is enabled: writing to object-storage, try reading first from object-storage and, then, from file system");
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
411 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
412 else if (hybridModeString == "WriteToFileSystem")
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
413 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
414 hybridMode = HybridMode_WriteToFileSystem;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
415 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": WriteToFileSystem HybridMode is enabled: writing to file system, try reading first from file system and, then, from object-storage");
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
416 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
417 else
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
418 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
419 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode is disabled enabled: writing to object-storage and reading only from object-storage");
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
420 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
421
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
422 if (IsReadFromDisk())
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
423 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
424 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined");
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
425 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": HybridMode: reading from file system is enabled, source: " + fileSystemRootPath);
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
426 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
427
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
428 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string());
33
Alain Mazy
parents: 31 27
diff changeset
429
Alain Mazy
parents: 31 27
diff changeset
430 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/')
Alain Mazy
parents: 31 27
diff changeset
431 {
Alain Mazy
parents: 31 27
diff changeset
432 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath);
Alain Mazy
parents: 31 27
diff changeset
433 return -1;
Alain Mazy
parents: 31 27
diff changeset
434 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
435
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
436 std::string objecstStoragePluginName = StoragePluginFactory::GetStoragePluginName();
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
437 if (hybridMode == HybridMode_WriteToFileSystem)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
438 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
439 objecstStoragePluginName += " (Secondary: object-storage)";
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
440 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
441 else if (hybridMode == HybridMode_WriteToObjectStorage)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
442 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
443 objecstStoragePluginName += " (Primary: object-storage)";
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
444 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
445
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
446 std::unique_ptr<IStoragePlugin> objectStoragePlugin(StoragePluginFactory::CreateStoragePlugin(objecstStoragePluginName, orthancConfig));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
447
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
448 if (objectStoragePlugin.get() == nullptr)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
449 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
450 return -1;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
451 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
452
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
453 objectStoragePlugin->SetRootPath(objectsRootPath);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
454
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
455 std::unique_ptr<IStoragePlugin> fileSystemStoragePlugin;
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
456 if (IsHybridModeEnabled())
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
457 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
458 bool fsync = orthancConfig.GetBooleanValue("SyncStorageArea", true);
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
459
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
460 std::string filesystemStoragePluginName = StoragePluginFactory::GetStoragePluginName();
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
461 if (hybridMode == HybridMode_WriteToFileSystem)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
462 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
463 filesystemStoragePluginName += " (Primary: file-system)";
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
464 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
465 else if (hybridMode == HybridMode_WriteToObjectStorage)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
466 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
467 filesystemStoragePluginName += " (Secondary: file-system)";
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
468 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
469
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
470 fileSystemStoragePlugin.reset(new FileSystemStoragePlugin(filesystemStoragePluginName, fileSystemRootPath, fsync));
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
471 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
472
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
473 if (hybridMode == HybridMode_Disabled || hybridMode == HybridMode_WriteToObjectStorage)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
474 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
475 primaryPlugin.reset(objectStoragePlugin.release());
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
476
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
477 if (hybridMode == HybridMode_WriteToObjectStorage)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
478 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
479 secondaryPlugin.reset(fileSystemStoragePlugin.release());
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
480 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
481 }
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
482 else if (hybridMode == HybridMode_WriteToFileSystem)
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
483 {
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
484 primaryPlugin.reset(fileSystemStoragePlugin.release());
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
485 secondaryPlugin.reset(objectStoragePlugin.release());
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
486 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
487
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
488 if (pluginSection.IsSection(ENCRYPTION_SECTION))
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
489 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
490 OrthancPlugins::OrthancConfiguration cryptoSection;
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
491 pluginSection.GetSection(cryptoSection, ENCRYPTION_SECTION);
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
492
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
493 crypto.reset(EncryptionConfigurator::CreateEncryptionHelpers(cryptoSection));
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
494 cryptoEnabled = crypto.get() != nullptr;
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
495 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
496
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
497 if (cryptoEnabled)
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
498 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
499 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is enabled");
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
500 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
501 else
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
502 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
503 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": client-side encryption is disabled");
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
504 }
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
505
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
506
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
507 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
508
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
509 if (cryptoEnabled)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
510 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
511 // with encrypted file, we do not want to support ReadRange. Therefore, we register the old interface
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
512 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
513 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
514 else
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
515 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
516 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
517 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
518 }
27
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
519 catch (Orthanc::OrthancException& e)
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
520 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
521 LOG(ERROR) << "Exception while creating the object storage plugin: " << e.What();
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
522 return -1;
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
523 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
524
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
525 return 0;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
526 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
527
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
528
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
529 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
530 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
531 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is finalizing");
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
532 primaryPlugin.reset();
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 57
diff changeset
533 secondaryPlugin.reset();
57
ba1be668e475 fix initialization of the aws static library
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
534 Orthanc::FinalizeFramework();
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
535 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
536
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
537
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
538 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
539 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
540 return StoragePluginFactory::GetStoragePluginName();
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
541 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
542
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
543
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
544 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
545 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
546 return PLUGIN_VERSION;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
547 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
548 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
549