comparison OrthancServer/OrthancInitialization.cpp @ 808:2d9a000aa3a6

update/delete peers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 May 2014 16:30:47 +0200
parents 566a2fb3c1fb
children 401a9633e492
comparison
equal deleted inserted replaced
807:566a2fb3c1fb 808:2d9a000aa3a6
291 !modalities.isMember(name)) 291 !modalities.isMember(name))
292 { 292 {
293 throw OrthancException(ErrorCode_BadFileFormat); 293 throw OrthancException(ErrorCode_BadFileFormat);
294 } 294 }
295 295
296 std::string url; 296 peer.FromJson(modalities[name]);
297
298 try
299 {
300 url = modalities[name].get(0u, "").asString();
301
302 if (modalities[name].size() == 1)
303 {
304 peer.SetUsername("");
305 peer.SetPassword("");
306 }
307 else if (modalities[name].size() == 3)
308 {
309 peer.SetUsername(modalities[name].get(1u, "").asString());
310 peer.SetPassword(modalities[name].get(2u, "").asString());
311 }
312 else
313 {
314 throw OrthancException(ErrorCode_BadFileFormat);
315 }
316 }
317 catch (...)
318 {
319 throw OrthancException(ErrorCode_BadFileFormat);
320 }
321
322 if (url.size() != 0 && url[url.size() - 1] != '/')
323 {
324 url += '/';
325 }
326
327 peer.SetUrl(url);
328 } 297 }
329 catch (OrthancException& e) 298 catch (OrthancException& e)
330 { 299 {
331 LOG(ERROR) << "Syntax error in the definition of peer \"" << name 300 LOG(ERROR) << "Syntax error in the definition of peer \"" << name
332 << "\". Please check your configuration file."; 301 << "\". Please check your configuration file.";
595 throw OrthancException(ErrorCode_BadFileFormat); 564 throw OrthancException(ErrorCode_BadFileFormat);
596 } 565 }
597 566
598 modalities.removeMember(symbolicName.c_str()); 567 modalities.removeMember(symbolicName.c_str());
599 } 568 }
569
570
571 void UpdatePeer(const OrthancPeerParameters& peer)
572 {
573 boost::mutex::scoped_lock lock(globalMutex_);
574
575 if (!configuration_->isMember("OrthancPeers"))
576 {
577 throw OrthancException(ErrorCode_BadFileFormat);
578 }
579
580 Json::Value& peers = (*configuration_) ["OrthancPeers"];
581 if (peers.type() != Json::objectValue)
582 {
583 throw OrthancException(ErrorCode_BadFileFormat);
584 }
585
586 peers.removeMember(peer.GetName().c_str());
587
588 Json::Value v;
589 peer.ToJson(v);
590 peers[peer.GetName()] = v;
591 }
592
593
594 void RemovePeer(const std::string& symbolicName)
595 {
596 boost::mutex::scoped_lock lock(globalMutex_);
597
598 if (!configuration_->isMember("OrthancPeers"))
599 {
600 throw OrthancException(ErrorCode_BadFileFormat);
601 }
602
603 Json::Value& peers = (*configuration_) ["OrthancPeers"];
604 if (peers.type() != Json::objectValue)
605 {
606 throw OrthancException(ErrorCode_BadFileFormat);
607 }
608
609 peers.removeMember(symbolicName.c_str());
610 }
600 } 611 }