comparison OrthancServer/OrthancInitialization.cpp @ 484:b8ace6fc1d1f

preparation for handling Orthanc peers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Jul 2013 12:51:27 +0200
parents 4aae0261515e
children bdbde1fbfab3
comparison
equal deleted inserted replaced
483:8c3573d28868 484:b8ace6fc1d1f
258 } 258 }
259 } 259 }
260 260
261 261
262 262
263 void GetListOfDicomModalities(std::set<std::string>& target) 263 void GetOrthancPeer(const std::string& name,
264 std::string& url,
265 std::string& username,
266 std::string& password)
267 {
268 boost::mutex::scoped_lock lock(globalMutex_);
269
270 if (!configuration_->isMember("OrthancPeers"))
271 {
272 throw OrthancException("");
273 }
274
275 const Json::Value& modalities = (*configuration_) ["OrthancPeers"];
276 if (modalities.type() != Json::objectValue ||
277 !modalities.isMember(name))
278 {
279 throw OrthancException("");
280 }
281
282 try
283 {
284 url = modalities[name].get(0u, "").asString();
285 username = modalities[name].get(1u, "").asString();
286 password = modalities[name].get(2u, "").asString();
287 }
288 catch (...)
289 {
290 throw OrthancException("Badly formatted Orthanc peer");
291 }
292 }
293
294
295 static bool ReadKeys(std::set<std::string>& target,
296 const char* parameter,
297 bool onlyAlphanumeric)
264 { 298 {
265 boost::mutex::scoped_lock lock(globalMutex_); 299 boost::mutex::scoped_lock lock(globalMutex_);
266 300
267 target.clear(); 301 target.clear();
268 302
269 if (!configuration_->isMember("DicomModalities")) 303 if (!configuration_->isMember(parameter))
270 { 304 {
271 return; 305 return true;
272 } 306 }
273 307
274 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; 308 const Json::Value& modalities = (*configuration_) [parameter];
275 if (modalities.type() != Json::objectValue) 309 if (modalities.type() != Json::objectValue)
276 { 310 {
277 throw OrthancException("Badly formatted list of DICOM modalities"); 311 throw OrthancException(ErrorCode_BadFileFormat);
278 } 312 }
279 313
280 Json::Value::Members members = modalities.getMemberNames(); 314 Json::Value::Members members = modalities.getMemberNames();
281 for (size_t i = 0; i < members.size(); i++) 315 for (size_t i = 0; i < members.size(); i++)
282 { 316 {
283 for (size_t j = 0; j < members[i].size(); j++) 317 if (onlyAlphanumeric)
284 { 318 {
285 if (!isalnum(members[i][j]) && members[i][j] != '-') 319 for (size_t j = 0; j < members[i].size(); j++)
286 { 320 {
287 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities"); 321 if (!isalnum(members[i][j]) && members[i][j] != '-')
322 {
323 return false;
324 }
288 } 325 }
289 } 326 }
290 327
291 target.insert(members[i]); 328 target.insert(members[i]);
329 }
330
331 return true;
332 }
333
334
335 void GetListOfDicomModalities(std::set<std::string>& target)
336 {
337 if (!ReadKeys(target, "DicomModalities", true))
338 {
339 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of the modalities");
340 }
341 }
342
343
344 void GetListOfOrthancPeers(std::set<std::string>& target)
345 {
346 if (!ReadKeys(target, "OrthancPeers", true))
347 {
348 throw OrthancException("Only alphanumeric and dash characters are allowed in the names of Orthanc peers");
292 } 349 }
293 } 350 }
294 351
295 352
296 353