annotate Common/StoragePlugin.cpp @ 56:b922ae86bbe1

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