Mercurial > hg > orthanc
annotate OrthancServer/OrthancInitialization.cpp @ 814:aeee9cc66dd9
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 08 May 2014 15:29:27 +0200 |
parents | 8a36c947490c |
children | a811bdf8b8eb |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 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" |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
38 #include "DicomProtocol/DicomServer.h" |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
39 #include "ServerEnumerations.h" |
0 | 40 |
41 #include <boost/lexical_cast.hpp> | |
42 #include <boost/filesystem.hpp> | |
43 #include <curl/curl.h> | |
44 #include <boost/thread.hpp> | |
108 | 45 #include <glog/logging.h> |
0 | 46 |
62 | 47 namespace Orthanc |
0 | 48 { |
49 static boost::mutex globalMutex_; | |
50 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
|
51 static boost::filesystem::path defaultDirectory_; |
0 | 52 |
806 | 53 |
0 | 54 static void ReadGlobalConfiguration(const char* configurationFile) |
55 { | |
56 configuration_.reset(new Json::Value); | |
57 | |
58 std::string content; | |
59 | |
60 if (configurationFile) | |
61 { | |
62 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
|
63 defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path(); |
660 | 64 LOG(WARNING) << "Using the configuration from: " << configurationFile; |
0 | 65 } |
66 else | |
67 { | |
660 | 68 #if ORTHANC_STANDALONE == 1 |
69 // No default path for the standalone configuration | |
70 LOG(WARNING) << "Using the default Orthanc configuration"; | |
71 return; | |
72 | |
73 #else | |
74 // In a non-standalone build, we use the | |
75 // "Resources/Configuration.json" from the Orthanc source code | |
76 | |
19 | 77 try |
78 { | |
660 | 79 boost::filesystem::path p = ORTHANC_PATH; |
80 p /= "Resources"; | |
81 p /= "Configuration.json"; | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
82 Toolbox::ReadFile(content, p.string()); |
660 | 83 LOG(WARNING) << "Using the configuration from: " << p.string(); |
87
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 catch (OrthancException&) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
86 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
87 // No configuration file found, give up with empty configuration |
660 | 88 LOG(WARNING) << "Using the default Orthanc configuration"; |
19 | 89 return; |
90 } | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
91 #endif |
0 | 92 } |
93 | |
94 Json::Reader reader; | |
95 if (!reader.parse(content, *configuration_)) | |
96 { | |
62 | 97 throw OrthancException("Unable to read the configuration file"); |
0 | 98 } |
99 } | |
100 | |
101 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
102 static void RegisterUserMetadata() |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
103 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
104 if (configuration_->isMember("UserMetadata")) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
105 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
106 const Json::Value& parameter = (*configuration_) ["UserMetadata"]; |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
107 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
108 Json::Value::Members members = parameter.getMemberNames(); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
109 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
|
110 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
111 std::string info = "\"" + members[i] + "\" = " + parameter[members[i]].toStyledString(); |
696
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
112 LOG(INFO) << "Registering user-defined metadata: " << info; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
113 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
114 if (!parameter[members[i]].asBool()) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
115 { |
439 | 116 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
|
117 throw OrthancException(ErrorCode_BadParameterType); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
118 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
119 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
120 int metadata = parameter[members[i]].asInt(); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
121 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
122 try |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
123 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
124 RegisterUserMetadata(metadata, members[i]); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
125 } |
657
5425bb6f1ea5
further cppcheck fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
126 catch (OrthancException&) |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
127 { |
439 | 128 LOG(ERROR) << "Cannot register this user-defined metadata: " << info; |
657
5425bb6f1ea5
further cppcheck fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
129 throw; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
130 } |
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 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
133 } |
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 |
696
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
136 static void RegisterUserContentType() |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
137 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
138 if (configuration_->isMember("UserContentType")) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
139 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
140 const Json::Value& parameter = (*configuration_) ["UserContentType"]; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
141 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
142 Json::Value::Members members = parameter.getMemberNames(); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
143 for (size_t i = 0; i < members.size(); i++) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
144 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
145 std::string info = "\"" + members[i] + "\" = " + parameter[members[i]].toStyledString(); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
146 LOG(INFO) << "Registering user-defined attachment type: " << info; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
147 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
148 if (!parameter[members[i]].asBool()) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
149 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
150 LOG(ERROR) << "Not a number in this user-defined attachment type: " << info; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
151 throw OrthancException(ErrorCode_BadParameterType); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
152 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
153 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
154 int contentType = parameter[members[i]].asInt(); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
155 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
156 try |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
157 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
158 RegisterUserContentType(contentType, members[i]); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
159 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
160 catch (OrthancException&) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
161 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
162 LOG(ERROR) << "Cannot register this user-defined attachment type: " << info; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
163 throw; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
164 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
165 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
166 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
167 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
168 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
169 |
62 | 170 void OrthancInitialize(const char* configurationFile) |
0 | 171 { |
172 boost::mutex::scoped_lock lock(globalMutex_); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
173 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
174 InitializeServerEnumerations(); |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
175 defaultDirectory_ = boost::filesystem::current_path(); |
0 | 176 ReadGlobalConfiguration(configurationFile); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
177 |
457 | 178 HttpClient::GlobalInitialize(); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
179 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
180 RegisterUserMetadata(); |
696
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
181 RegisterUserContentType(); |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
182 |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
183 DicomServer::InitializeDictionary(); |
0 | 184 } |
185 | |
186 | |
187 | |
62 | 188 void OrthancFinalize() |
0 | 189 { |
190 boost::mutex::scoped_lock lock(globalMutex_); | |
457 | 191 HttpClient::GlobalFinalize(); |
0 | 192 configuration_.reset(NULL); |
193 } | |
194 | |
195 | |
196 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
197 std::string Configuration::GetGlobalStringParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
198 const std::string& defaultValue) |
0 | 199 { |
200 boost::mutex::scoped_lock lock(globalMutex_); | |
201 | |
202 if (configuration_->isMember(parameter)) | |
203 { | |
204 return (*configuration_) [parameter].asString(); | |
205 } | |
206 else | |
207 { | |
208 return defaultValue; | |
209 } | |
210 } | |
211 | |
212 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
213 int Configuration::GetGlobalIntegerParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
214 int defaultValue) |
0 | 215 { |
216 boost::mutex::scoped_lock lock(globalMutex_); | |
217 | |
218 if (configuration_->isMember(parameter)) | |
219 { | |
220 return (*configuration_) [parameter].asInt(); | |
221 } | |
222 else | |
223 { | |
224 return defaultValue; | |
225 } | |
226 } | |
227 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
228 |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
229 bool Configuration::GetGlobalBoolParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
230 bool defaultValue) |
23 | 231 { |
232 boost::mutex::scoped_lock lock(globalMutex_); | |
233 | |
234 if (configuration_->isMember(parameter)) | |
235 { | |
236 return (*configuration_) [parameter].asBool(); | |
237 } | |
238 else | |
239 { | |
240 return defaultValue; | |
241 } | |
242 } | |
243 | |
244 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
245 void Configuration::GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
246 const std::string& name) |
0 | 247 { |
248 boost::mutex::scoped_lock lock(globalMutex_); | |
249 | |
250 if (!configuration_->isMember("DicomModalities")) | |
251 { | |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
252 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 253 } |
254 | |
255 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | |
256 if (modalities.type() != Json::objectValue || | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
257 !modalities.isMember(name)) |
0 | 258 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
259 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 260 } |
261 | |
262 try | |
263 { | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
264 modality.FromJson(modalities[name]); |
0 | 265 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
266 catch (OrthancException& e) |
0 | 267 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
268 LOG(ERROR) << "Syntax error in the definition of modality \"" << name |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
269 << "\". Please check your configuration file."; |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
270 throw e; |
0 | 271 } |
272 } | |
273 | |
274 | |
275 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
276 void Configuration::GetOrthancPeer(OrthancPeerParameters& peer, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
277 const std::string& name) |
484
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 boost::mutex::scoped_lock lock(globalMutex_); |
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 if (!configuration_->isMember("OrthancPeers")) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
282 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
283 throw OrthancException(ErrorCode_BadFileFormat); |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
284 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
285 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
286 try |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
287 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
288 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
289 if (modalities.type() != Json::objectValue || |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
290 !modalities.isMember(name)) |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
291 { |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
292 throw OrthancException(ErrorCode_BadFileFormat); |
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
293 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
294 |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
295 peer.FromJson(modalities[name]); |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
296 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
297 catch (OrthancException& e) |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
298 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
299 LOG(ERROR) << "Syntax error in the definition of peer \"" << name |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
300 << "\". Please check your configuration file."; |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
301 throw e; |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
302 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
303 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
304 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
305 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
306 static bool ReadKeys(std::set<std::string>& target, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
307 const char* parameter, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
308 bool onlyAlphanumeric) |
0 | 309 { |
310 boost::mutex::scoped_lock lock(globalMutex_); | |
311 | |
312 target.clear(); | |
313 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
314 if (!configuration_->isMember(parameter)) |
0 | 315 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
316 return true; |
0 | 317 } |
318 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
319 const Json::Value& modalities = (*configuration_) [parameter]; |
0 | 320 if (modalities.type() != Json::objectValue) |
321 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
322 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 323 } |
324 | |
325 Json::Value::Members members = modalities.getMemberNames(); | |
326 for (size_t i = 0; i < members.size(); i++) | |
327 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
328 if (onlyAlphanumeric) |
0 | 329 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
330 for (size_t j = 0; j < members[i].size(); j++) |
0 | 331 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
332 if (!isalnum(members[i][j]) && members[i][j] != '-') |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
333 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
334 return false; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
335 } |
0 | 336 } |
337 } | |
338 | |
339 target.insert(members[i]); | |
340 } | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
341 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
342 return true; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
343 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
344 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
345 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
346 void Configuration::GetListOfDicomModalities(std::set<std::string>& target) |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
347 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
348 if (!ReadKeys(target, "DicomModalities", true)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
349 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
350 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
|
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 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
354 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
355 void Configuration::GetListOfOrthancPeers(std::set<std::string>& target) |
484
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 if (!ReadKeys(target, "OrthancPeers", true)) |
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 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
|
360 } |
0 | 361 } |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
362 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
363 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
364 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
365 void Configuration::SetupRegisteredUsers(MongooseServer& httpServer) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
366 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
367 boost::mutex::scoped_lock lock(globalMutex_); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
368 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
369 httpServer.ClearUsers(); |
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 if (!configuration_->isMember("RegisteredUsers")) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
372 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
373 return; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
374 } |
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 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
377 if (users.type() != Json::objectValue) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
378 { |
62 | 379 throw OrthancException("Badly formatted list of users"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
380 } |
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 Json::Value::Members usernames = users.getMemberNames(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
383 for (size_t i = 0; i < usernames.size(); i++) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
384 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
385 const std::string& username = usernames[i]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
386 std::string password = users[username].asString(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
387 httpServer.RegisterUser(username.c_str(), password.c_str()); |
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 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
390 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
391 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
392 std::string Configuration::InterpretRelativePath(const std::string& baseDirectory, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
393 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
|
394 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
395 boost::filesystem::path base(baseDirectory); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
396 boost::filesystem::path relative(relativePath); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
397 |
428 | 398 /** |
399 The following lines should be equivalent to this one: | |
400 | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
401 return (base / relative).string(); |
428 | 402 |
403 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
|
404 make the proper path resolution when "baseDirectory" is an |
428 | 405 absolute path. So, a hack is used below. |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
406 **/ |
428 | 407 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
408 if (relative.is_absolute()) |
427 | 409 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
410 return relative.string(); |
427 | 411 } |
412 else | |
413 { | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
414 return (base / relative).string(); |
427 | 415 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
416 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
417 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
418 std::string Configuration::InterpretStringParameterAsPath(const std::string& parameter) |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
419 { |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
420 boost::mutex::scoped_lock lock(globalMutex_); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
421 return InterpretRelativePath(defaultDirectory_.string(), parameter); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
422 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
423 |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
424 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
425 void Configuration::GetGlobalListOfStringsParameter(std::list<std::string>& target, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
426 const std::string& key) |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
427 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
428 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
|
429 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
430 target.clear(); |
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 if (!configuration_->isMember(key)) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
433 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
434 return; |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
435 } |
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 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
|
438 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
439 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
|
440 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
441 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
|
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 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
|
445 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
446 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
|
447 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
448 } |
613 | 449 |
450 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
451 bool Configuration::IsSameAETitle(const std::string& aet1, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
452 const std::string& aet2) |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
453 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
454 if (GetGlobalBoolParameter("StrictAetComparison", false)) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
455 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
456 // Case-sensitive matching |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
457 return aet1 == aet2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
458 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
459 else |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
460 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
461 // Case-insensitive matching (default) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
462 std::string tmp1, tmp2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
463 Toolbox::ToLowerCase(tmp1, aet1); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
464 Toolbox::ToLowerCase(tmp2, aet2); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
465 return tmp1 == tmp2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
466 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
467 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
468 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
469 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
470 bool Configuration::LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
471 const std::string& aet) |
613 | 472 { |
473 std::set<std::string> modalities; | |
474 GetListOfDicomModalities(modalities); | |
475 | |
476 for (std::set<std::string>::const_iterator | |
656 | 477 it = modalities.begin(); it != modalities.end(); ++it) |
613 | 478 { |
479 try | |
480 { | |
806 | 481 GetDicomModalityUsingSymbolicName(modality, *it); |
725 | 482 |
806 | 483 if (IsSameAETitle(aet, modality.GetApplicationEntityTitle())) |
613 | 484 { |
617 | 485 return true; |
613 | 486 } |
487 } | |
488 catch (OrthancException&) | |
489 { | |
490 } | |
491 } | |
492 | |
617 | 493 return false; |
494 } | |
495 | |
496 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
497 bool Configuration::IsKnownAETitle(const std::string& aet) |
617 | 498 { |
806 | 499 RemoteModalityParameters modality; |
500 return LookupDicomModalityUsingAETitle(modality, aet); | |
617 | 501 } |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
502 |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
503 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
504 RemoteModalityParameters Configuration::GetModalityUsingSymbolicName(const std::string& name) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
505 { |
806 | 506 RemoteModalityParameters modality; |
507 GetDicomModalityUsingSymbolicName(modality, name); | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
508 |
806 | 509 return modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
510 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
511 |
773 | 512 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
513 RemoteModalityParameters Configuration::GetModalityUsingAet(const std::string& aet) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
514 { |
806 | 515 RemoteModalityParameters modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
516 |
806 | 517 if (LookupDicomModalityUsingAETitle(modality, aet)) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
518 { |
806 | 519 return modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
520 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
521 else |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
522 { |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
523 throw OrthancException("Unknown modality for AET: " + aet); |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
524 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
525 } |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
526 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
527 |
812 | 528 void Configuration::UpdateModality(const std::string& symbolicName, |
529 const RemoteModalityParameters& modality) | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
530 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
531 boost::mutex::scoped_lock lock(globalMutex_); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
532 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
533 if (!configuration_->isMember("DicomModalities")) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
534 { |
814 | 535 (*configuration_) ["DicomModalities"] = Json::objectValue; |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
536 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
537 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
538 Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
539 if (modalities.type() != Json::objectValue) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
540 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
541 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
542 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
543 |
812 | 544 modalities.removeMember(symbolicName); |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
545 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
546 Json::Value v; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
547 modality.ToJson(v); |
812 | 548 modalities[symbolicName] = v; |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
549 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
550 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
551 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
552 void Configuration::RemoveModality(const std::string& symbolicName) |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
553 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
554 boost::mutex::scoped_lock lock(globalMutex_); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
555 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
556 if (!configuration_->isMember("DicomModalities")) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
557 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
558 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
559 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
560 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
561 Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
562 if (modalities.type() != Json::objectValue) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
563 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
564 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
565 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
566 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
567 modalities.removeMember(symbolicName.c_str()); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
568 } |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
569 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
570 |
812 | 571 void Configuration::UpdatePeer(const std::string& symbolicName, |
572 const OrthancPeerParameters& peer) | |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
573 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
574 boost::mutex::scoped_lock lock(globalMutex_); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
575 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
576 if (!configuration_->isMember("OrthancPeers")) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
577 { |
814 | 578 (*configuration_) ["OrthancPeers"] = Json::objectValue; |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
579 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
580 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
581 Json::Value& peers = (*configuration_) ["OrthancPeers"]; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
582 if (peers.type() != Json::objectValue) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
583 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
584 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
585 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
586 |
812 | 587 peers.removeMember(symbolicName); |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
588 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
589 Json::Value v; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
590 peer.ToJson(v); |
812 | 591 peers[symbolicName] = v; |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
592 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
593 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
594 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
595 void Configuration::RemovePeer(const std::string& symbolicName) |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
596 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
597 boost::mutex::scoped_lock lock(globalMutex_); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
598 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
599 if (!configuration_->isMember("OrthancPeers")) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
600 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
601 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
602 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
603 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
604 Json::Value& peers = (*configuration_) ["OrthancPeers"]; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
605 if (peers.type() != Json::objectValue) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
606 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
607 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
608 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
609 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
610 peers.removeMember(symbolicName.c_str()); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
611 } |
0 | 612 } |