Mercurial > hg > orthanc
comparison OrthancServer/OrthancInitialization.cpp @ 62:a70bb32802ae orthanc-renaming
renaming Server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 16 Sep 2012 09:33:19 +0200 |
parents | 6da7fc87efaa |
children | 8517e2c44283 |
comparison
equal
deleted
inserted
replaced
61:d1c511efd6b1 | 62:a70bb32802ae |
---|---|
1 /** | 1 /** |
2 * Palanthir - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 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 | 7 * modify it under the terms of the GNU General Public License as |
16 * You should have received a copy of the GNU General Public License | 16 * You should have received a copy of the GNU General Public License |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 **/ | 18 **/ |
19 | 19 |
20 | 20 |
21 #include "PalanthirInitialization.h" | 21 #include "OrthancInitialization.h" |
22 | 22 |
23 #include "../Core/PalanthirException.h" | 23 #include "../Core/OrthancException.h" |
24 #include "../Core/Toolbox.h" | 24 #include "../Core/Toolbox.h" |
25 | 25 |
26 #include <boost/lexical_cast.hpp> | 26 #include <boost/lexical_cast.hpp> |
27 #include <boost/filesystem.hpp> | 27 #include <boost/filesystem.hpp> |
28 #include <curl/curl.h> | 28 #include <curl/curl.h> |
29 #include <boost/thread.hpp> | 29 #include <boost/thread.hpp> |
30 | 30 |
31 namespace Palanthir | 31 namespace Orthanc |
32 { | 32 { |
33 static const char* CONFIGURATION_FILE = "Configuration.json"; | 33 static const char* CONFIGURATION_FILE = "Configuration.json"; |
34 | 34 |
35 static boost::mutex globalMutex_; | 35 static boost::mutex globalMutex_; |
36 static std::auto_ptr<Json::Value> configuration_; | 36 static std::auto_ptr<Json::Value> configuration_; |
48 } | 48 } |
49 else | 49 else |
50 { | 50 { |
51 try | 51 try |
52 { | 52 { |
53 #if PALANTHIR_STANDALONE == 0 | 53 #if ORTHANC_STANDALONE == 0 |
54 boost::filesystem::path p = PALANTHIR_PATH; | 54 boost::filesystem::path p = ORTHANC_PATH; |
55 p /= "Resources"; | 55 p /= "Resources"; |
56 p /= CONFIGURATION_FILE; | 56 p /= CONFIGURATION_FILE; |
57 Toolbox::ReadFile(content, p.string()); | 57 Toolbox::ReadFile(content, p.string()); |
58 #else | 58 #else |
59 Toolbox::ReadFile(content, CONFIGURATION_FILE); | 59 Toolbox::ReadFile(content, CONFIGURATION_FILE); |
60 #endif | 60 #endif |
61 } | 61 } |
62 catch (PalanthirException&) | 62 catch (OrthancException&) |
63 { | 63 { |
64 // No configuration file found, give up with empty configuration | 64 // No configuration file found, give up with empty configuration |
65 return; | 65 return; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 Json::Reader reader; | 69 Json::Reader reader; |
70 if (!reader.parse(content, *configuration_)) | 70 if (!reader.parse(content, *configuration_)) |
71 { | 71 { |
72 throw PalanthirException("Unable to read the configuration file"); | 72 throw OrthancException("Unable to read the configuration file"); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 void PalanthirInitialize(const char* configurationFile) | 77 void OrthancInitialize(const char* configurationFile) |
78 { | 78 { |
79 boost::mutex::scoped_lock lock(globalMutex_); | 79 boost::mutex::scoped_lock lock(globalMutex_); |
80 ReadGlobalConfiguration(configurationFile); | 80 ReadGlobalConfiguration(configurationFile); |
81 curl_global_init(CURL_GLOBAL_ALL); | 81 curl_global_init(CURL_GLOBAL_ALL); |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 | 85 |
86 void PalanthirFinalize() | 86 void OrthancFinalize() |
87 { | 87 { |
88 boost::mutex::scoped_lock lock(globalMutex_); | 88 boost::mutex::scoped_lock lock(globalMutex_); |
89 curl_global_cleanup(); | 89 curl_global_cleanup(); |
90 configuration_.reset(NULL); | 90 configuration_.reset(NULL); |
91 } | 91 } |
148 { | 148 { |
149 boost::mutex::scoped_lock lock(globalMutex_); | 149 boost::mutex::scoped_lock lock(globalMutex_); |
150 | 150 |
151 if (!configuration_->isMember("DicomModalities")) | 151 if (!configuration_->isMember("DicomModalities")) |
152 { | 152 { |
153 throw PalanthirException(""); | 153 throw OrthancException(""); |
154 } | 154 } |
155 | 155 |
156 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | 156 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
157 if (modalities.type() != Json::objectValue || | 157 if (modalities.type() != Json::objectValue || |
158 !modalities.isMember(name)) | 158 !modalities.isMember(name)) |
159 { | 159 { |
160 throw PalanthirException(""); | 160 throw OrthancException(""); |
161 } | 161 } |
162 | 162 |
163 try | 163 try |
164 { | 164 { |
165 aet = modalities[name].get(0u, "").asString(); | 165 aet = modalities[name].get(0u, "").asString(); |
166 address = modalities[name].get(1u, "").asString(); | 166 address = modalities[name].get(1u, "").asString(); |
167 port = modalities[name].get(2u, "").asInt(); | 167 port = modalities[name].get(2u, "").asInt(); |
168 } | 168 } |
169 catch (...) | 169 catch (...) |
170 { | 170 { |
171 throw PalanthirException("Badly formatted DICOM modality"); | 171 throw OrthancException("Badly formatted DICOM modality"); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 | 176 |
186 } | 186 } |
187 | 187 |
188 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | 188 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
189 if (modalities.type() != Json::objectValue) | 189 if (modalities.type() != Json::objectValue) |
190 { | 190 { |
191 throw PalanthirException("Badly formatted list of DICOM modalities"); | 191 throw OrthancException("Badly formatted list of DICOM modalities"); |
192 } | 192 } |
193 | 193 |
194 Json::Value::Members members = modalities.getMemberNames(); | 194 Json::Value::Members members = modalities.getMemberNames(); |
195 for (size_t i = 0; i < members.size(); i++) | 195 for (size_t i = 0; i < members.size(); i++) |
196 { | 196 { |
197 for (size_t j = 0; j < members[i].size(); j++) | 197 for (size_t j = 0; j < members[i].size(); j++) |
198 { | 198 { |
199 if (!isalnum(members[i][j]) && members[i][j] != '-') | 199 if (!isalnum(members[i][j]) && members[i][j] != '-') |
200 { | 200 { |
201 throw PalanthirException("Only alphanumeric and dash characters are allowed in the names of the modalities"); | 201 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities"); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 target.insert(members[i]); | 205 target.insert(members[i]); |
206 } | 206 } |
220 } | 220 } |
221 | 221 |
222 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; | 222 const Json::Value& users = (*configuration_) ["RegisteredUsers"]; |
223 if (users.type() != Json::objectValue) | 223 if (users.type() != Json::objectValue) |
224 { | 224 { |
225 throw PalanthirException("Badly formatted list of users"); | 225 throw OrthancException("Badly formatted list of users"); |
226 } | 226 } |
227 | 227 |
228 Json::Value::Members usernames = users.getMemberNames(); | 228 Json::Value::Members usernames = users.getMemberNames(); |
229 for (size_t i = 0; i < usernames.size(); i++) | 229 for (size_t i = 0; i < usernames.size(); i++) |
230 { | 230 { |