annotate Common/StoragePlugin.cpp @ 43:4c71c5e2edce

fix memory handling in legacy read
author Alain Mazy <am@osimis.io>
date Fri, 19 Mar 2021 17:37:46 +0100
parents 50d0be413c42
children b922ae86bbe1
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
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
19 #if GOOGLE_STORAGE_PLUGIN==1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
20 #include "../Google/GoogleStoragePlugin.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
21 #define StoragePluginFactory GoogleStoragePluginFactory
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
22 #elif AZURE_STORAGE_PLUGIN==1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23 #include "../Azure/AzureBlobStoragePlugin.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
24 #define StoragePluginFactory AzureBlobStoragePluginFactory
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
25 #elif AWS_STORAGE_PLUGIN==1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
26 #include "../Aws/AwsS3StoragePlugin.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
27 #define StoragePluginFactory AwsS3StoragePluginFactory
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
28 #else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29 #pragma message(error "define a plugin")
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
30 #endif
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
31
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32 #include <string.h>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
33 #include <stdio.h>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
34 #include <string>
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
35
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
36 #include <iostream>
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
37 #include <boost/filesystem.hpp>
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
38 #include <boost/filesystem/fstream.hpp>
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
39
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
40 #include "../Common/EncryptionHelpers.h"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
41 #include "../Common/EncryptionConfigurator.h"
35
8a7a5defd5d0 upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
42
8a7a5defd5d0 upgrade orthanc framework to 1.8.2 in AWS S3 plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 33
diff changeset
43 #include <Logging.h>
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
44 #include <SystemToolbox.h>
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
45
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
46 static std::unique_ptr<IStoragePlugin> plugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
47
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
48 static std::unique_ptr<EncryptionHelpers> crypto;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
49 static bool cryptoEnabled = false;
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
50 static std::string fileSystemRootPath;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
51 static bool migrationFromFileSystemEnabled = false;
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
52 static std::string objectsRootPath;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
53
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
54
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
55 static OrthancPluginErrorCode StorageCreate(const char* uuid,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
56 const void* content,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57 int64_t size,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
58 OrthancPluginContentType type)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
60 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
61 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62 std::unique_ptr<IStoragePlugin::IWriter> writer(plugin->GetWriterForObject(uuid, type, cryptoEnabled));
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
63
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
64 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
65 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
66 std::string encryptedFile;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
67
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
68 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
69 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
70 crypto->Encrypt(encryptedFile, (const char*)content, size);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
71 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72 catch (EncryptionException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
73 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
74 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while encrypting object " + std::string(uuid) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
75 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
76 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
77
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78 writer->Write(encryptedFile.data(), encryptedFile.size());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
80 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
81 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 writer->Write(reinterpret_cast<const char*>(content), size);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
86 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
87 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while creating object " + std::string(uuid) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
88 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
89 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
90
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
91 return OrthancPluginErrorCode_Success;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
92 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
93
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
94
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
95 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.
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
96 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
97 OrthancPluginContentType type,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
98 uint64_t rangeStart)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
99 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
100 assert(!cryptoEnabled);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
101
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
102 try
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
103 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
104 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
105 reader->ReadRange(reinterpret_cast<char*>(target->data), target->size, rangeStart);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
106 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
107 catch (StoragePluginException& ex)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
108 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
109 if (migrationFromFileSystemEnabled)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
110 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
111 try
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
112 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
113 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + ex.what() + ", will now try to read it from legacy orthanc storage");
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
114 std::string path = BaseStoragePlugin::GetOrthancFileSystemPath(uuid, fileSystemRootPath);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
115
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
116 std::string stringBuffer;
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
117 Orthanc::SystemToolbox::ReadFileRange(stringBuffer, path, rangeStart, rangeStart + target->size, true);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
118
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
119 memcpy(target->data, stringBuffer.data(), stringBuffer.size());
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
120
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
121 return OrthancPluginErrorCode_Success;
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
122 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
123 catch(Orthanc::OrthancException& e)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
124 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
125 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(e.What()));
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
126 return OrthancPluginErrorCode_StorageAreaPlugin;
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 }
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 return OrthancPluginErrorCode_Success;
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
131 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
132
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
133
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
134 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.
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
135 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
136 OrthancPluginContentType type)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
137 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
138 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
139 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
140 std::unique_ptr<IStoragePlugin::IReader> reader(plugin->GetReaderForObject(uuid, type, cryptoEnabled));
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
141
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
142 size_t fileSize = reader->GetSize();
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
143 size_t size;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
144
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
145 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
146 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
147 size = fileSize - crypto->OVERHEAD_SIZE;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
148 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
149 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
150 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
151 size = fileSize;
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
152 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
153
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
154 if (size <= 0)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
155 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
156 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ", size of file is too small: " + boost::lexical_cast<std::string>(fileSize) + " bytes");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
157 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
158 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
159
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
160 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, size) != OrthancPluginErrorCode_Success)
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
161 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
162 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": 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
163 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
164 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
165
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
166 if (cryptoEnabled)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
167 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
168 std::vector<char> encrypted(fileSize);
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
169 reader->ReadWhole(encrypted.data(), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
170
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
171 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
172 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
173 crypto->Decrypt(reinterpret_cast<char*>(target->data), encrypted.data(), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
174 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
175 catch (EncryptionException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
176 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
177 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while decrypting object " + std::string(uuid) + ": " + ex.what());
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
178 return OrthancPluginErrorCode_StorageAreaPlugin;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
179 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
180 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
181 else
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
182 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
183 reader->ReadWhole(reinterpret_cast<char*>(target->data), fileSize);
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
184 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
185 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
186 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
187 {
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
188 if (migrationFromFileSystemEnabled)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
189 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
190 try
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
191 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
192 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + ex.what() + ", will now try to read it from legacy orthanc storage");
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
193 std::string path = BaseStoragePlugin::GetOrthancFileSystemPath(uuid, fileSystemRootPath);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
194
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
195 std::string stringBuffer;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
196 Orthanc::SystemToolbox::ReadFile(stringBuffer, path);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
197
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
198 if (OrthancPluginCreateMemoryBuffer64(OrthancPlugins::GetGlobalContext(), target, stringBuffer.size()) != OrthancPluginErrorCode_Success)
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
199 {
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
200 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ", cannot allocate memory of size " + boost::lexical_cast<std::string>(stringBuffer.size()) + " bytes");
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
201 return OrthancPluginErrorCode_StorageAreaPlugin;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
202 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
203
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
204 memcpy(target->data, stringBuffer.data(), stringBuffer.size());
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
205
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
206 return OrthancPluginErrorCode_Success;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
207 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
208 catch(Orthanc::OrthancException& e)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
209 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
210 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + std::string(e.What()));
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
211 return OrthancPluginErrorCode_StorageAreaPlugin;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
212 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
213 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
214 else
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
215 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
216 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while reading object " + std::string(uuid) + ": " + ex.what());
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
217 return OrthancPluginErrorCode_StorageAreaPlugin;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
218 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
219 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
220
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
221 return OrthancPluginErrorCode_Success;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
222 }
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 static OrthancPluginErrorCode StorageReadWholeLegacy(void** content,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
225 int64_t* size,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
226 const char* uuid,
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
227 OrthancPluginContentType type)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
228 {
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
229 OrthancPluginMemoryBuffer64 buffer;
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
230 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
231
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
232 if (result == OrthancPluginErrorCode_Success)
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
233 {
43
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
234 *size = buffer.size;
4c71c5e2edce fix memory handling in legacy read
Alain Mazy <am@osimis.io>
parents: 39
diff changeset
235 *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
236 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
237
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
238 return result;
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
239 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
240
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
241
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
242 static OrthancPluginErrorCode StorageRemove(const char* uuid,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
243 OrthancPluginContentType type)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
244 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
245 try
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
246 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
247 plugin->DeleteObject(uuid, type, cryptoEnabled);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
248 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
249 catch (StoragePluginException& ex)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
250 {
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
251 if (migrationFromFileSystemEnabled)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
252 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
253 try
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
254 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
255 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + ex.what() + ", will now try to delete it from legacy orthanc storage");
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
256 namespace fs = boost::filesystem;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
257
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
258 fs::path path = BaseStoragePlugin::GetOrthancFileSystemPath(uuid, fileSystemRootPath);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
259
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
260 try
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
261 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
262 fs::remove(path);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
263 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
264 catch (...)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
265 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
266 // Ignore the error
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
267 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
268
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
269 // Remove the two parent directories, ignoring the error code if
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
270 // these directories are not empty
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
271
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
272 try
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
273 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
274 boost::system::error_code err;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
275 fs::remove(path.parent_path(), err);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
276 fs::remove(path.parent_path().parent_path(), err);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
277 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
278 catch (...)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
279 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
280 // Ignore the error
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
281 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
282
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
283 return OrthancPluginErrorCode_Success;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
284 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
285 catch(Orthanc::OrthancException& e)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
286 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
287 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + std::string(e.What()));
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
288 return OrthancPluginErrorCode_StorageAreaPlugin;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
289 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
290 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
291 else
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
292 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
293 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": error while deleting object " + std::string(uuid) + ": " + ex.what());
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
294 return OrthancPluginErrorCode_StorageAreaPlugin;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
295 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
296 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
297
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
298 return OrthancPluginErrorCode_Success;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
299 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
300
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
301
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
302 extern "C"
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
303 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
304 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
305 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
306 OrthancPlugins::SetGlobalContext(context);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
307
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
308 Orthanc::Logging::InitializePluginContext(context);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
309
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
310 OrthancPlugins::OrthancConfiguration orthancConfig;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
311
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
312 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is initializing");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
313
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
314 /* Check the version of the Orthanc core */
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
315 if (OrthancPluginCheckVersion(context) == 0)
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
316 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
317 char info[1024];
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
318 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
319 context->orthancVersion,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
320 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
321 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
322 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
323 OrthancPlugins::LogError(info);
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
324 return -1;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
325 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
326
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
327 try
8
987cb95c1aee Prevent Orthanc to start if plugin fails to start
Alain Mazy
parents: 1
diff changeset
328 {
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
329 plugin.reset(StoragePluginFactory::CreateStoragePlugin(orthancConfig));
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
330
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
331 if (plugin.get() == nullptr)
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
332 {
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
333 return -1;
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
334 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
335
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
336 const char* pluginSectionName = plugin->GetConfigurationSectionName();
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
337 static const char* const ENCRYPTION_SECTION = "StorageEncryption";
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
338
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
339 if (orthancConfig.IsSection(pluginSectionName))
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
340 {
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
341 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
342 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
343
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
344 migrationFromFileSystemEnabled = pluginSection.GetBooleanValue("MigrationFromFileSystemEnabled", false);
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
345
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
346 if (migrationFromFileSystemEnabled)
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
347 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
348 fileSystemRootPath = orthancConfig.GetStringValue("StorageDirectory", "OrthancStorageNotDefined");
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
349 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + ": migration from file system enabled, source: " + fileSystemRootPath);
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
350 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
351
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
352 objectsRootPath = pluginSection.GetStringValue("RootPath", std::string());
33
Alain Mazy
parents: 31 27
diff changeset
353
Alain Mazy
parents: 31 27
diff changeset
354 if (objectsRootPath.size() >= 1 && objectsRootPath[0] == '/')
Alain Mazy
parents: 31 27
diff changeset
355 {
Alain Mazy
parents: 31 27
diff changeset
356 OrthancPlugins::LogError(std::string(StoragePluginFactory::GetStoragePluginName()) + ": The RootPath shall not start with a '/': " + objectsRootPath);
Alain Mazy
parents: 31 27
diff changeset
357 return -1;
Alain Mazy
parents: 31 27
diff changeset
358 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
359
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
360 plugin->SetRootPath(objectsRootPath);
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
361
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
362 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
363 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
364 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
365 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
366
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
367 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
368 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
369 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
370
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
371 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
372 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
373 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
374 }
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
375 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
376 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
377 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
378 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
379 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents: 8
diff changeset
380
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
381 if (cryptoEnabled)
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
382 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
383 // 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
384 OrthancPluginRegisterStorageArea(context, StorageCreate, StorageReadWholeLegacy, StorageRemove);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
385 }
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
386 else
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
387 {
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
388 OrthancPluginRegisterStorageArea2(context, StorageCreate, StorageReadWhole, StorageReadRange, StorageRemove);
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 37
diff changeset
389 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
390 }
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
391 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
392 {
e1f52b851827 Added "VirtualAddressing" configuration option in the AWS S3 plugin (for compatibility with minio)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 20
diff changeset
393 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
394 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
395 }
1
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
396
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
397 return 0;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
398 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
399
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
400
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
401 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
402 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
403 OrthancPlugins::LogWarning(std::string(StoragePluginFactory::GetStoragePluginName()) + " plugin is finalizing");
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
404 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
405
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
406
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
407 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
408 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
409 return StoragePluginFactory::GetStoragePluginName();
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
410 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
411
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
412
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
413 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
414 {
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
415 return PLUGIN_VERSION;
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
416 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
417 }
fc26a8fc54d5 initial release
Alain Mazy <alain@mazy.be>
parents:
diff changeset
418