Mercurial > hg > orthanc
annotate OrthancServer/OrthancInitialization.cpp @ 485:bdbde1fbfab3
send resources through HTTP
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 16 Jul 2013 13:48:33 +0200 |
parents | b8ace6fc1d1f |
children | 1b2cdc855bd3 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
399 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
62 | 33 #include "OrthancInitialization.h" |
0 | 34 |
476 | 35 #include "../Core/HttpClient.h" |
62 | 36 #include "../Core/OrthancException.h" |
0 | 37 #include "../Core/Toolbox.h" |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
38 #include "ServerEnumerations.h" |
0 | 39 |
40 #include <boost/lexical_cast.hpp> | |
41 #include <boost/filesystem.hpp> | |
42 #include <curl/curl.h> | |
43 #include <boost/thread.hpp> | |
108 | 44 #include <glog/logging.h> |
0 | 45 |
62 | 46 namespace Orthanc |
0 | 47 { |
48 static const char* CONFIGURATION_FILE = "Configuration.json"; | |
49 | |
50 static boost::mutex globalMutex_; | |
51 static std::auto_ptr<Json::Value> configuration_; | |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
52 static boost::filesystem::path defaultDirectory_; |
0 | 53 |
54 | |
55 static void ReadGlobalConfiguration(const char* configurationFile) | |
56 { | |
57 configuration_.reset(new Json::Value); | |
58 | |
59 std::string content; | |
60 | |
61 if (configurationFile) | |
62 { | |
63 Toolbox::ReadFile(content, configurationFile); | |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
64 defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path(); |
108 | 65 LOG(INFO) << "Using the configuration from: " << configurationFile; |
0 | 66 } |
67 else | |
68 { | |
91 | 69 #if 0 && ORTHANC_STANDALONE == 1 && defined(__linux) |
70 // Unused anymore | |
88 | 71 // Under Linux, try and open "../../etc/orthanc/Configuration.json" |
19 | 72 try |
73 { | |
88 | 74 boost::filesystem::path p = Toolbox::GetDirectoryOfExecutable(); |
75 p = p.parent_path().parent_path(); | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
76 p /= "etc"; |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
77 p /= "orthanc"; |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
78 p /= CONFIGURATION_FILE; |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
79 |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
80 Toolbox::ReadFile(content, p.string()); |
108 | 81 LOG(INFO) << "Using the configuration from: " << p.string(); |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
82 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
83 catch (OrthancException&) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
84 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
85 // No configuration file found, give up with empty configuration |
108 | 86 LOG(INFO) << "Using the default Orthanc configuration"; |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
87 return; |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
88 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
89 |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
90 #elif ORTHANC_STANDALONE == 1 |
91 | 91 // No default path for the standalone configuration |
108 | 92 LOG(INFO) << "Using the default Orthanc configuration"; |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
93 return; |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
94 |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
95 #else |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
96 // In a non-standalone build, we use the |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
97 // "Resources/Configuration.json" from the Orthanc distribution |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
98 try |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
99 { |
62 | 100 boost::filesystem::path p = ORTHANC_PATH; |
19 | 101 p /= "Resources"; |
102 p /= CONFIGURATION_FILE; | |
103 Toolbox::ReadFile(content, p.string()); | |
108 | 104 LOG(INFO) << "Using the configuration from: " << p.string(); |
19 | 105 } |
62 | 106 catch (OrthancException&) |
19 | 107 { |
108 // No configuration file found, give up with empty configuration | |
108 | 109 LOG(INFO) << "Using the default Orthanc configuration"; |
19 | 110 return; |
111 } | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
112 #endif |
0 | 113 } |
114 | |
115 Json::Reader reader; | |
116 if (!reader.parse(content, *configuration_)) | |
117 { | |
62 | 118 throw OrthancException("Unable to read the configuration file"); |
0 | 119 } |
120 } | |
121 | |
122 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
123 static void RegisterUserMetadata() |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
124 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
125 if (configuration_->isMember("UserMetadata")) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
126 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
127 const Json::Value& parameter = (*configuration_) ["UserMetadata"]; |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
128 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
129 Json::Value::Members members = parameter.getMemberNames(); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
130 for (size_t i = 0; i < members.size(); i++) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
131 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
132 std::string info = "\"" + members[i] + "\" = " + parameter[members[i]].toStyledString(); |
439 | 133 LOG(INFO) << "Registering user-defined metadata: " << info; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
134 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
135 if (!parameter[members[i]].asBool()) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
136 { |
439 | 137 LOG(ERROR) << "Not a number in this user-defined metadata: " << info; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
138 throw OrthancException(ErrorCode_BadParameterType); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
139 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
140 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
141 int metadata = parameter[members[i]].asInt(); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
142 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
143 try |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
144 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
145 RegisterUserMetadata(metadata, members[i]); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
146 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
147 catch (OrthancException e) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
148 { |
439 | 149 LOG(ERROR) << "Cannot register this user-defined metadata: " << info; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
150 throw e; |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
151 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
152 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
153 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
154 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
155 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
156 |
62 | 157 void OrthancInitialize(const char* configurationFile) |
0 | 158 { |
159 boost::mutex::scoped_lock lock(globalMutex_); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
160 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
161 InitializeServerEnumerations(); |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
162 defaultDirectory_ = boost::filesystem::current_path(); |
0 | 163 ReadGlobalConfiguration(configurationFile); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
164 |
457 | 165 HttpClient::GlobalInitialize(); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
166 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
167 RegisterUserMetadata(); |
0 | 168 } |
169 | |
170 | |
171 | |
62 | 172 void OrthancFinalize() |
0 | 173 { |
174 boost::mutex::scoped_lock lock(globalMutex_); | |
457 | 175 HttpClient::GlobalFinalize(); |
0 | 176 configuration_.reset(NULL); |
177 } | |
178 | |
179 | |
180 | |
181 std::string GetGlobalStringParameter(const std::string& parameter, | |
182 const std::string& defaultValue) | |
183 { | |
184 boost::mutex::scoped_lock lock(globalMutex_); | |
185 | |
186 if (configuration_->isMember(parameter)) | |
187 { | |
188 return (*configuration_) [parameter].asString(); | |
189 } | |
190 else | |
191 { | |
192 return defaultValue; | |
193 } | |
194 } | |
195 | |
196 | |
197 int GetGlobalIntegerParameter(const std::string& parameter, | |
198 int defaultValue) | |
199 { | |
200 boost::mutex::scoped_lock lock(globalMutex_); | |
201 | |
202 if (configuration_->isMember(parameter)) | |
203 { | |
204 return (*configuration_) [parameter].asInt(); | |
205 } | |
206 else | |
207 { | |
208 return defaultValue; | |
209 } | |
210 } | |
211 | |
23 | 212 bool GetGlobalBoolParameter(const std::string& parameter, |
213 bool defaultValue) | |
214 { | |
215 boost::mutex::scoped_lock lock(globalMutex_); | |
216 | |
217 if (configuration_->isMember(parameter)) | |
218 { | |
219 return (*configuration_) [parameter].asBool(); | |
220 } | |
221 else | |
222 { | |
223 return defaultValue; | |
224 } | |
225 } | |
226 | |
227 | |
0 | 228 |
229 | |
230 void GetDicomModality(const std::string& name, | |
231 std::string& aet, | |
232 std::string& address, | |
233 int& port) | |
234 { | |
235 boost::mutex::scoped_lock lock(globalMutex_); | |
236 | |
237 if (!configuration_->isMember("DicomModalities")) | |
238 { | |
62 | 239 throw OrthancException(""); |
0 | 240 } |
241 | |
242 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | |
243 if (modalities.type() != Json::objectValue || | |
244 !modalities.isMember(name)) | |
245 { | |
62 | 246 throw OrthancException(""); |
0 | 247 } |
248 | |
249 try | |
250 { | |
251 aet = modalities[name].get(0u, "").asString(); | |
252 address = modalities[name].get(1u, "").asString(); | |
253 port = modalities[name].get(2u, "").asInt(); | |
254 } | |
255 catch (...) | |
256 { | |
62 | 257 throw OrthancException("Badly formatted DICOM modality"); |
0 | 258 } |
259 } | |
260 | |
261 | |
262 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
263 void GetOrthancPeer(const std::string& name, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
264 std::string& url, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
265 std::string& username, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
266 std::string& password) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
267 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
268 boost::mutex::scoped_lock lock(globalMutex_); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
269 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
270 if (!configuration_->isMember("OrthancPeers")) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
271 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
272 throw OrthancException(""); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
273 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
274 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
275 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
276 if (modalities.type() != Json::objectValue || |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
277 !modalities.isMember(name)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
278 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
279 throw OrthancException(""); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
280 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
281 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
282 try |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
283 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
284 url = modalities[name].get(0u, "").asString(); |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
285 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
286 if (modalities[name].size() == 1) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
287 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
288 username = ""; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
289 password = ""; |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
290 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
291 else if (modalities[name].size() == 3) |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
292 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
293 username = modalities[name].get(1u, "").asString(); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
294 password = modalities[name].get(2u, "").asString(); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
295 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
296 else |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
297 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
298 throw OrthancException(ErrorCode_BadFileFormat); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
299 } |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
300 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
301 catch (...) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
302 { |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
303 throw OrthancException(ErrorCode_BadFileFormat); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
304 } |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
305 |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
306 if (url.size() != 0 && url[url.size() - 1] != '/') |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
307 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
308 url += '/'; |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
309 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
310 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
311 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
312 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
313 static bool ReadKeys(std::set<std::string>& target, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
314 const char* parameter, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
315 bool onlyAlphanumeric) |
0 | 316 { |
317 boost::mutex::scoped_lock lock(globalMutex_); | |
318 | |
319 target.clear(); | |
320 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
321 if (!configuration_->isMember(parameter)) |
0 | 322 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
323 return true; |
0 | 324 } |
325 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
326 const Json::Value& modalities = (*configuration_) [parameter]; |
0 | 327 if (modalities.type() != Json::objectValue) |
328 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
329 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 330 } |
331 | |
332 Json::Value::Members members = modalities.getMemberNames(); | |
333 for (size_t i = 0; i < members.size(); i++) | |
334 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
335 if (onlyAlphanumeric) |
0 | 336 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
337 for (size_t j = 0; j < members[i].size(); j++) |
0 | 338 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
339 if (!isalnum(members[i][j]) && members[i][j] != '-') |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
340 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
341 return false; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
342 } |
0 | 343 } |
344 } | |
345 | |
346 target.insert(members[i]); | |
347 } | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
348 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
349 return true; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
350 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
351 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
352 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
353 void GetListOfDicomModalities(std::set<std::string>& target) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
354 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
355 if (!ReadKeys(target, "DicomModalities", true)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
356 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
357 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities"); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
358 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
359 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
360 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
361 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
362 void GetListOfOrthancPeers(std::set<std::string>& target) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
363 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
364 if (!ReadKeys(target, "OrthancPeers", true)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
365 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
366 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of Orthanc peers"); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
367 } |
0 | 368 } |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
369 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
370 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
371 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
372 void SetupRegisteredUsers(MongooseServer& httpServer) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
373 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
374 boost::mutex::scoped_lock lock(globalMutex_); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
375 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
376 httpServer.ClearUsers(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
377 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
378 if (!configuration_->isMember("RegisteredUsers")) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
379 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
380 return; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
381 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
382 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
383 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
384 if (users.type() != Json::objectValue) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
385 { |
62 | 386 throw OrthancException("Badly formatted list of users"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
387 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
388 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
389 Json::Value::Members usernames = users.getMemberNames(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
390 for (size_t i = 0; i < usernames.size(); i++) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
391 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
392 const std::string& username = usernames[i]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
393 std::string password = users[username].asString(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
394 httpServer.RegisterUser(username.c_str(), password.c_str()); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
395 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
396 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
397 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
398 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
399 std::string InterpretRelativePath(const std::string& baseDirectory, |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
400 const std::string& relativePath) |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
401 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
402 boost::filesystem::path base(baseDirectory); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
403 boost::filesystem::path relative(relativePath); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
404 |
428 | 405 /** |
406 The following lines should be equivalent to this one: | |
407 | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
408 return (base / relative).string(); |
428 | 409 |
410 However, for some unknown reason, some versions of Boost do not | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
411 make the proper path resolution when "baseDirectory" is an |
428 | 412 absolute path. So, a hack is used below. |
413 **/ | |
414 | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
415 if (relative.is_absolute()) |
427 | 416 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
417 return relative.string(); |
427 | 418 } |
419 else | |
420 { | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
421 return (base / relative).string(); |
427 | 422 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
423 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
424 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
425 std::string InterpretStringParameterAsPath(const std::string& parameter) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
426 { |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
427 boost::mutex::scoped_lock lock(globalMutex_); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
428 return InterpretRelativePath(defaultDirectory_.string(), parameter); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
429 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
430 |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
431 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
432 void GetGlobalListOfStringsParameter(std::list<std::string>& target, |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
433 const std::string& key) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
434 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
435 boost::mutex::scoped_lock lock(globalMutex_); |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
436 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
437 target.clear(); |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
438 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
439 if (!configuration_->isMember(key)) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
440 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
441 return; |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
442 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
443 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
444 const Json::Value& lst = (*configuration_) [key]; |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
445 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
446 if (lst.type() != Json::arrayValue) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
447 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
448 throw OrthancException("Badly formatted list of strings"); |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
449 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
450 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
451 for (Json::Value::ArrayIndex i = 0; i < lst.size(); i++) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
452 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
453 target.push_back(lst[i].asString()); |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
454 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
455 } |
0 | 456 } |