Mercurial > hg > orthanc
annotate OrthancServer/OrthancInitialization.cpp @ 1294:910478b2d4e4
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 06 Feb 2015 13:48:05 +0100 |
parents | 6e7e5ed91c2d |
children | 59b603763f43 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1275
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1275
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 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 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "PrecompiledHeadersServer.h" |
62 | 34 #include "OrthancInitialization.h" |
0 | 35 |
476 | 36 #include "../Core/HttpClient.h" |
62 | 37 #include "../Core/OrthancException.h" |
0 | 38 #include "../Core/Toolbox.h" |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
39 #include "DicomProtocol/DicomServer.h" |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
40 #include "ServerEnumerations.h" |
0 | 41 |
42 #include <boost/lexical_cast.hpp> | |
43 #include <boost/filesystem.hpp> | |
44 #include <curl/curl.h> | |
45 #include <boost/thread.hpp> | |
108 | 46 #include <glog/logging.h> |
0 | 47 |
1274 | 48 #include "DatabaseWrapper.h" |
49 #include "../Core/FileStorage/FilesystemStorage.h" | |
50 | |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
51 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
52 #if ORTHANC_JPEG_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
53 #include <dcmtk/dcmjpeg/djdecode.h> |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
54 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
55 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
56 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
57 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
58 #include <dcmtk/dcmjpls/djdecode.h> |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
59 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
60 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
61 |
62 | 62 namespace Orthanc |
0 | 63 { |
64 static boost::mutex globalMutex_; | |
65 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
|
66 static boost::filesystem::path defaultDirectory_; |
1145
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
67 static std::string configurationAbsolutePath_; |
0 | 68 |
806 | 69 |
0 | 70 static void ReadGlobalConfiguration(const char* configurationFile) |
71 { | |
72 configuration_.reset(new Json::Value); | |
73 | |
74 std::string content; | |
75 | |
76 if (configurationFile) | |
77 { | |
78 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
|
79 defaultDirectory_ = boost::filesystem::path(configurationFile).parent_path(); |
660 | 80 LOG(WARNING) << "Using the configuration from: " << configurationFile; |
1145
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
81 configurationAbsolutePath_ = boost::filesystem::absolute(configurationFile).string(); |
0 | 82 } |
83 else | |
84 { | |
660 | 85 #if ORTHANC_STANDALONE == 1 |
86 // No default path for the standalone configuration | |
87 LOG(WARNING) << "Using the default Orthanc configuration"; | |
88 return; | |
89 | |
90 #else | |
91 // In a non-standalone build, we use the | |
92 // "Resources/Configuration.json" from the Orthanc source code | |
93 | |
19 | 94 try |
95 { | |
660 | 96 boost::filesystem::path p = ORTHANC_PATH; |
97 p /= "Resources"; | |
98 p /= "Configuration.json"; | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
99 Toolbox::ReadFile(content, p.string()); |
660 | 100 LOG(WARNING) << "Using the configuration from: " << p.string(); |
1145
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
101 configurationAbsolutePath_ = boost::filesystem::absolute(p).string(); |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
102 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
103 catch (OrthancException&) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
104 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
105 // No configuration file found, give up with empty configuration |
660 | 106 LOG(WARNING) << "Using the default Orthanc configuration"; |
19 | 107 return; |
108 } | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
62
diff
changeset
|
109 #endif |
0 | 110 } |
111 | |
1145
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
112 |
0 | 113 Json::Reader reader; |
114 if (!reader.parse(content, *configuration_)) | |
115 { | |
62 | 116 throw OrthancException("Unable to read the configuration file"); |
0 | 117 } |
118 } | |
119 | |
120 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
121 static void RegisterUserMetadata() |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
122 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
123 if (configuration_->isMember("UserMetadata")) |
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 const Json::Value& parameter = (*configuration_) ["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 Json::Value::Members members = parameter.getMemberNames(); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
128 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
|
129 { |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
130 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
|
131 LOG(INFO) << "Registering user-defined metadata: " << info; |
435
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 if (!parameter[members[i]].asBool()) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
134 { |
439 | 135 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
|
136 throw OrthancException(ErrorCode_BadParameterType); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
137 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
138 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
139 int metadata = parameter[members[i]].asInt(); |
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 try |
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 RegisterUserMetadata(metadata, members[i]); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
144 } |
657
5425bb6f1ea5
further cppcheck fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
145 catch (OrthancException&) |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
146 { |
439 | 147 LOG(ERROR) << "Cannot register this user-defined metadata: " << info; |
657
5425bb6f1ea5
further cppcheck fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
656
diff
changeset
|
148 throw; |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
149 } |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
150 } |
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 |
696
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
155 static void RegisterUserContentType() |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
156 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
157 if (configuration_->isMember("UserContentType")) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
158 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
159 const Json::Value& parameter = (*configuration_) ["UserContentType"]; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
160 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
161 Json::Value::Members members = parameter.getMemberNames(); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
162 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
|
163 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
164 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
|
165 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
|
166 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
167 if (!parameter[members[i]].asBool()) |
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 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
|
170 throw OrthancException(ErrorCode_BadParameterType); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
171 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
172 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
173 int contentType = parameter[members[i]].asInt(); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
174 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
175 try |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
176 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
177 RegisterUserContentType(contentType, members[i]); |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
178 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
179 catch (OrthancException&) |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
180 { |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
181 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
|
182 throw; |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
183 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
184 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
185 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
186 } |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
187 |
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
188 |
1275
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
189 static std::string GetStringValue(const Json::Value& configuration, |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
190 const std::string& key, |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
191 const std::string& defaultValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
192 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
193 if (configuration.type() != Json::objectValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
194 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
195 throw OrthancException(ErrorCode_BadFileFormat); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
196 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
197 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
198 if (!configuration.isMember(key)) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
199 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
200 return defaultValue; |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
201 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
202 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
203 if (configuration[key].type() != Json::stringValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
204 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
205 throw OrthancException(ErrorCode_BadFileFormat); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
206 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
207 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
208 return configuration[key].asString(); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
209 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
210 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
211 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
212 static int GetIntegerValue(const Json::Value& configuration, |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
213 const std::string& key, |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
214 int defaultValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
215 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
216 if (configuration.type() != Json::objectValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
217 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
218 throw OrthancException(ErrorCode_BadFileFormat); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
219 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
220 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
221 if (!configuration.isMember(key)) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
222 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
223 return defaultValue; |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
224 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
225 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
226 if (configuration[key].type() != Json::intValue) |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
227 { |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
228 throw OrthancException(ErrorCode_BadFileFormat); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
229 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
230 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
231 return configuration[key].asInt(); |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
232 } |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
233 |
4287285709d1
new functions for initialization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1274
diff
changeset
|
234 |
62 | 235 void OrthancInitialize(const char* configurationFile) |
0 | 236 { |
237 boost::mutex::scoped_lock lock(globalMutex_); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
238 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
239 InitializeServerEnumerations(); |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
240 defaultDirectory_ = boost::filesystem::current_path(); |
0 | 241 ReadGlobalConfiguration(configurationFile); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
242 |
457 | 243 HttpClient::GlobalInitialize(); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
244 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
245 RegisterUserMetadata(); |
696
4c1860179cc5
dictionary of user-defined content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
690
diff
changeset
|
246 RegisterUserContentType(); |
685
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
247 |
b01cc78caba4
possibility to disable the DICOM/HTTP servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
660
diff
changeset
|
248 DicomServer::InitializeDictionary(); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
249 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
250 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
251 LOG(WARNING) << "Registering JPEG Lossless codecs"; |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
252 DJLSDecoderRegistration::registerCodecs(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
253 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
254 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
255 #if ORTHANC_JPEG_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
256 LOG(WARNING) << "Registering JPEG codecs"; |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
257 DJDecoderRegistration::registerCodecs(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
258 #endif |
0 | 259 } |
260 | |
261 | |
262 | |
62 | 263 void OrthancFinalize() |
0 | 264 { |
265 boost::mutex::scoped_lock lock(globalMutex_); | |
457 | 266 HttpClient::GlobalFinalize(); |
0 | 267 configuration_.reset(NULL); |
847
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
268 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
269 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
270 // Unregister JPEG-LS codecs |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
271 DJLSDecoderRegistration::cleanup(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
272 #endif |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
273 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
274 #if ORTHANC_JPEG_ENABLED == 1 |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
275 // Unregister JPEG codecs |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
276 DJDecoderRegistration::cleanup(); |
03ea55da7429
fully functional JPEG-LS conversion
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
277 #endif |
0 | 278 } |
279 | |
280 | |
281 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
282 std::string Configuration::GetGlobalStringParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
283 const std::string& defaultValue) |
0 | 284 { |
285 boost::mutex::scoped_lock lock(globalMutex_); | |
286 | |
287 if (configuration_->isMember(parameter)) | |
288 { | |
289 return (*configuration_) [parameter].asString(); | |
290 } | |
291 else | |
292 { | |
293 return defaultValue; | |
294 } | |
295 } | |
296 | |
297 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
298 int Configuration::GetGlobalIntegerParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
299 int defaultValue) |
0 | 300 { |
301 boost::mutex::scoped_lock lock(globalMutex_); | |
302 | |
303 if (configuration_->isMember(parameter)) | |
304 { | |
305 return (*configuration_) [parameter].asInt(); | |
306 } | |
307 else | |
308 { | |
309 return defaultValue; | |
310 } | |
311 } | |
312 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
313 |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
314 bool Configuration::GetGlobalBoolParameter(const std::string& parameter, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
315 bool defaultValue) |
23 | 316 { |
317 boost::mutex::scoped_lock lock(globalMutex_); | |
318 | |
319 if (configuration_->isMember(parameter)) | |
320 { | |
321 return (*configuration_) [parameter].asBool(); | |
322 } | |
323 else | |
324 { | |
325 return defaultValue; | |
326 } | |
327 } | |
328 | |
329 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
330 void Configuration::GetDicomModalityUsingSymbolicName(RemoteModalityParameters& modality, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
331 const std::string& name) |
0 | 332 { |
333 boost::mutex::scoped_lock lock(globalMutex_); | |
334 | |
335 if (!configuration_->isMember("DicomModalities")) | |
336 { | |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
337 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 338 } |
339 | |
340 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | |
341 if (modalities.type() != Json::objectValue || | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
342 !modalities.isMember(name)) |
0 | 343 { |
1007
871c49c9b11d
lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
344 LOG(ERROR) << "No modality with symbolic name: " << name; |
871c49c9b11d
lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
345 throw OrthancException(ErrorCode_InexistentItem); |
0 | 346 } |
347 | |
348 try | |
349 { | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
350 modality.FromJson(modalities[name]); |
0 | 351 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
352 catch (OrthancException& e) |
0 | 353 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
354 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
|
355 << "\". Please check your configuration file."; |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
847
diff
changeset
|
356 throw; |
0 | 357 } |
358 } | |
359 | |
360 | |
361 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
362 void Configuration::GetOrthancPeer(OrthancPeerParameters& peer, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
363 const std::string& name) |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
364 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
365 boost::mutex::scoped_lock lock(globalMutex_); |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
366 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
367 if (!configuration_->isMember("OrthancPeers")) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
368 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
369 throw OrthancException(ErrorCode_BadFileFormat); |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
370 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
371 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
372 try |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
373 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
374 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
375 if (modalities.type() != Json::objectValue || |
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
376 !modalities.isMember(name)) |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
377 { |
1007
871c49c9b11d
lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
378 LOG(ERROR) << "No peer with symbolic name: " << name; |
871c49c9b11d
lua routing is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
942
diff
changeset
|
379 throw OrthancException(ErrorCode_InexistentItem); |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
380 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
381 |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
382 peer.FromJson(modalities[name]); |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
383 } |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
384 catch (OrthancException& e) |
485
bdbde1fbfab3
send resources through HTTP
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
484
diff
changeset
|
385 { |
752
45715eadc2e0
port number as a string
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
386 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
|
387 << "\". Please check your configuration file."; |
942
b3f6fb1130cd
fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
847
diff
changeset
|
388 throw; |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
389 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
390 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
391 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
392 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
393 static bool ReadKeys(std::set<std::string>& target, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
394 const char* parameter, |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
395 bool onlyAlphanumeric) |
0 | 396 { |
397 boost::mutex::scoped_lock lock(globalMutex_); | |
398 | |
399 target.clear(); | |
400 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
401 if (!configuration_->isMember(parameter)) |
0 | 402 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
403 return true; |
0 | 404 } |
405 | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
406 const Json::Value& modalities = (*configuration_) [parameter]; |
0 | 407 if (modalities.type() != Json::objectValue) |
408 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
409 throw OrthancException(ErrorCode_BadFileFormat); |
0 | 410 } |
411 | |
412 Json::Value::Members members = modalities.getMemberNames(); | |
413 for (size_t i = 0; i < members.size(); i++) | |
414 { | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
415 if (onlyAlphanumeric) |
0 | 416 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
417 for (size_t j = 0; j < members[i].size(); j++) |
0 | 418 { |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
419 if (!isalnum(members[i][j]) && members[i][j] != '-') |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
420 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
421 return false; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
422 } |
0 | 423 } |
424 } | |
425 | |
426 target.insert(members[i]); | |
427 } | |
484
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
428 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
429 return true; |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
430 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
431 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
432 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
433 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
|
434 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
435 if (!ReadKeys(target, "DicomModalities", true)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
436 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
437 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
|
438 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
439 } |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
440 |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
441 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
442 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
|
443 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
444 if (!ReadKeys(target, "OrthancPeers", true)) |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
445 { |
b8ace6fc1d1f
preparation for handling Orthanc peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
446 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
|
447 } |
0 | 448 } |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
449 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
450 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
451 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
452 void Configuration::SetupRegisteredUsers(MongooseServer& httpServer) |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
453 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
454 boost::mutex::scoped_lock lock(globalMutex_); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
455 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
456 httpServer.ClearUsers(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
457 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
458 if (!configuration_->isMember("RegisteredUsers")) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
459 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
460 return; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
461 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
462 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
463 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
464 if (users.type() != Json::objectValue) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
465 { |
62 | 466 throw OrthancException("Badly formatted list of users"); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
467 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
468 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
469 Json::Value::Members usernames = users.getMemberNames(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
470 for (size_t i = 0; i < usernames.size(); i++) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
471 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
472 const std::string& username = usernames[i]; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
473 std::string password = users[username].asString(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
474 httpServer.RegisterUser(username.c_str(), password.c_str()); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
475 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
23
diff
changeset
|
476 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
477 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
478 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
479 std::string Configuration::InterpretRelativePath(const std::string& baseDirectory, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
480 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
|
481 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
482 boost::filesystem::path base(baseDirectory); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
483 boost::filesystem::path relative(relativePath); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
484 |
428 | 485 /** |
486 The following lines should be equivalent to this one: | |
487 | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
488 return (base / relative).string(); |
428 | 489 |
490 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
|
491 make the proper path resolution when "baseDirectory" is an |
428 | 492 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
|
493 **/ |
428 | 494 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
495 if (relative.is_absolute()) |
427 | 496 { |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
497 return relative.string(); |
427 | 498 } |
499 else | |
500 { | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
501 return (base / relative).string(); |
427 | 502 } |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
503 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
504 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
505 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
|
506 { |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
507 boost::mutex::scoped_lock lock(globalMutex_); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
508 return InterpretRelativePath(defaultDirectory_.string(), parameter); |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
509 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
428
diff
changeset
|
510 |
394
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
511 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
512 void Configuration::GetGlobalListOfStringsParameter(std::list<std::string>& target, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
513 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
|
514 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
515 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
|
516 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
517 target.clear(); |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
518 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
519 if (!configuration_->isMember(key)) |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
520 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
521 return; |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
522 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
523 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
524 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
|
525 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
526 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
|
527 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
528 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
|
529 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
530 |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
531 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
|
532 { |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
533 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
|
534 } |
9784f19f7e1b
path relative to configuration path, list of lua scripts
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
136
diff
changeset
|
535 } |
613 | 536 |
537 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
538 bool Configuration::IsSameAETitle(const std::string& aet1, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
539 const std::string& aet2) |
690
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
540 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
541 if (GetGlobalBoolParameter("StrictAetComparison", false)) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
542 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
543 // Case-sensitive matching |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
544 return aet1 == aet2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
545 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
546 else |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
547 { |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
548 // Case-insensitive matching (default) |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
549 std::string tmp1, tmp2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
550 Toolbox::ToLowerCase(tmp1, aet1); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
551 Toolbox::ToLowerCase(tmp2, aet2); |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
552 return tmp1 == tmp2; |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
553 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
554 } |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
555 |
2e67366aab83
case-insensitive matching of Application Entity Titles
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
556 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
557 bool Configuration::LookupDicomModalityUsingAETitle(RemoteModalityParameters& modality, |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
558 const std::string& aet) |
613 | 559 { |
560 std::set<std::string> modalities; | |
561 GetListOfDicomModalities(modalities); | |
562 | |
563 for (std::set<std::string>::const_iterator | |
656 | 564 it = modalities.begin(); it != modalities.end(); ++it) |
613 | 565 { |
566 try | |
567 { | |
806 | 568 GetDicomModalityUsingSymbolicName(modality, *it); |
725 | 569 |
806 | 570 if (IsSameAETitle(aet, modality.GetApplicationEntityTitle())) |
613 | 571 { |
617 | 572 return true; |
613 | 573 } |
574 } | |
575 catch (OrthancException&) | |
576 { | |
577 } | |
578 } | |
579 | |
617 | 580 return false; |
581 } | |
582 | |
583 | |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
584 bool Configuration::IsKnownAETitle(const std::string& aet) |
617 | 585 { |
806 | 586 RemoteModalityParameters modality; |
587 return LookupDicomModalityUsingAETitle(modality, aet); | |
617 | 588 } |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
589 |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
590 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
591 RemoteModalityParameters Configuration::GetModalityUsingSymbolicName(const std::string& name) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
592 { |
806 | 593 RemoteModalityParameters modality; |
594 GetDicomModalityUsingSymbolicName(modality, name); | |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
595 |
806 | 596 return modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
597 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
598 |
773 | 599 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
600 RemoteModalityParameters Configuration::GetModalityUsingAet(const std::string& aet) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
601 { |
806 | 602 RemoteModalityParameters modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
603 |
806 | 604 if (LookupDicomModalityUsingAETitle(modality, aet)) |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
605 { |
806 | 606 return modality; |
772
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
607 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
608 else |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
609 { |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
610 throw OrthancException("Unknown modality for AET: " + aet); |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
611 } |
31cc399c7762
RemoteModalityParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
771
diff
changeset
|
612 } |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
613 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
614 |
812 | 615 void Configuration::UpdateModality(const std::string& symbolicName, |
616 const RemoteModalityParameters& modality) | |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
617 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
618 boost::mutex::scoped_lock lock(globalMutex_); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
619 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
620 if (!configuration_->isMember("DicomModalities")) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
621 { |
814 | 622 (*configuration_) ["DicomModalities"] = Json::objectValue; |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
623 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
624 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
625 Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
626 if (modalities.type() != Json::objectValue) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
627 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
628 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
629 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
630 |
812 | 631 modalities.removeMember(symbolicName); |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
632 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
633 Json::Value v; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
634 modality.ToJson(v); |
812 | 635 modalities[symbolicName] = v; |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
636 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
637 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
638 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
639 void Configuration::RemoveModality(const std::string& symbolicName) |
807
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
640 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
641 boost::mutex::scoped_lock lock(globalMutex_); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
642 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
643 if (!configuration_->isMember("DicomModalities")) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
644 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
645 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
646 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
647 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
648 Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
649 if (modalities.type() != Json::objectValue) |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
650 { |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
651 throw OrthancException(ErrorCode_BadFileFormat); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
652 } |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
653 |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
654 modalities.removeMember(symbolicName.c_str()); |
566a2fb3c1fb
update/delete modalities
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
806
diff
changeset
|
655 } |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
656 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
657 |
812 | 658 void Configuration::UpdatePeer(const std::string& symbolicName, |
659 const OrthancPeerParameters& peer) | |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
660 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
661 boost::mutex::scoped_lock lock(globalMutex_); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
662 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
663 if (!configuration_->isMember("OrthancPeers")) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
664 { |
814 | 665 (*configuration_) ["OrthancPeers"] = Json::objectValue; |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
666 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
667 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
668 Json::Value& peers = (*configuration_) ["OrthancPeers"]; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
669 if (peers.type() != Json::objectValue) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
670 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
671 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
672 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
673 |
812 | 674 peers.removeMember(symbolicName); |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
675 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
676 Json::Value v; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
677 peer.ToJson(v); |
812 | 678 peers[symbolicName] = v; |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
679 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
680 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
681 |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
808
diff
changeset
|
682 void Configuration::RemovePeer(const std::string& symbolicName) |
808
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
683 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
684 boost::mutex::scoped_lock lock(globalMutex_); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
685 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
686 if (!configuration_->isMember("OrthancPeers")) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
687 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
688 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
689 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
690 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
691 Json::Value& peers = (*configuration_) ["OrthancPeers"]; |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
692 if (peers.type() != Json::objectValue) |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
693 { |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
694 throw OrthancException(ErrorCode_BadFileFormat); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
695 } |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
696 |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
697 peers.removeMember(symbolicName.c_str()); |
2d9a000aa3a6
update/delete peers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
807
diff
changeset
|
698 } |
1145
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
699 |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
700 |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
701 |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
702 const std::string& Configuration::GetConfigurationAbsolutePath() |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
703 { |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
704 return configurationAbsolutePath_; |
0479d02c6778
Plugins can retrieve the path to Orthanc and to its configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1007
diff
changeset
|
705 } |
1274 | 706 |
707 | |
708 static IDatabaseWrapper* CreateSQLiteWrapper() | |
709 { | |
710 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); | |
711 | |
712 // Open the database | |
713 boost::filesystem::path indexDirectory = Configuration::InterpretStringParameterAsPath( | |
714 Configuration::GetGlobalStringParameter("IndexDirectory", storageDirectoryStr)); | |
715 | |
716 LOG(WARNING) << "SQLite index directory: " << indexDirectory; | |
717 | |
718 try | |
719 { | |
720 boost::filesystem::create_directories(indexDirectory); | |
721 } | |
722 catch (boost::filesystem::filesystem_error) | |
723 { | |
724 } | |
725 | |
726 return new DatabaseWrapper(indexDirectory.string() + "/index"); | |
727 } | |
728 | |
729 | |
730 namespace | |
731 { | |
732 // Anonymous namespace to avoid clashes between compilation modules | |
733 | |
734 class FilesystemStorageWithoutDicom : public IStorageArea | |
735 { | |
736 private: | |
737 FilesystemStorage storage_; | |
738 | |
739 public: | |
740 FilesystemStorageWithoutDicom(const std::string& path) : storage_(path) | |
741 { | |
742 } | |
743 | |
744 virtual void Create(const std::string& uuid, | |
745 const void* content, | |
746 size_t size, | |
747 FileContentType type) | |
748 { | |
749 if (type != FileContentType_Dicom) | |
750 { | |
751 storage_.Create(uuid, content, size, type); | |
752 } | |
753 } | |
754 | |
755 virtual void Read(std::string& content, | |
756 const std::string& uuid, | |
757 FileContentType type) | |
758 { | |
759 if (type != FileContentType_Dicom) | |
760 { | |
761 storage_.Read(content, uuid, type); | |
762 } | |
763 else | |
764 { | |
765 throw OrthancException(ErrorCode_UnknownResource); | |
766 } | |
767 } | |
768 | |
769 virtual void Remove(const std::string& uuid, | |
770 FileContentType type) | |
771 { | |
772 if (type != FileContentType_Dicom) | |
773 { | |
774 storage_.Remove(uuid, type); | |
775 } | |
776 } | |
777 }; | |
778 } | |
779 | |
780 | |
781 static IStorageArea* CreateFilesystemStorage() | |
782 { | |
783 std::string storageDirectoryStr = Configuration::GetGlobalStringParameter("StorageDirectory", "OrthancStorage"); | |
784 | |
785 boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr); | |
786 LOG(WARNING) << "Storage directory: " << storageDirectory; | |
787 | |
788 if (Configuration::GetGlobalBoolParameter("StoreDicom", true)) | |
789 { | |
790 return new FilesystemStorage(storageDirectory.string()); | |
791 } | |
792 else | |
793 { | |
794 LOG(WARNING) << "The DICOM files will not be stored, Orthanc running in index-only mode"; | |
795 return new FilesystemStorageWithoutDicom(storageDirectory.string()); | |
796 } | |
797 } | |
798 | |
799 | |
800 IDatabaseWrapper* Configuration::CreateDatabaseWrapper() | |
801 { | |
802 return CreateSQLiteWrapper(); | |
803 } | |
804 | |
805 | |
806 IStorageArea* Configuration::CreateStorageArea() | |
807 { | |
808 return CreateFilesystemStorage(); | |
809 } | |
0 | 810 } |