# HG changeset patch # User Sebastien Jodogne # Date 1399473047 -7200 # Node ID 2d9a000aa3a68a61ee2e16dee1e49579cb70253d # Parent 566a2fb3c1fb29b8074867d2163c091ecd6f3c3b update/delete peers diff -r 566a2fb3c1fb -r 2d9a000aa3a6 CMakeLists.txt --- a/CMakeLists.txt Wed May 07 15:54:23 2014 +0200 +++ b/CMakeLists.txt Wed May 07 16:30:47 2014 +0200 @@ -215,6 +215,7 @@ OrthancServer/Internals/MoveScp.cpp OrthancServer/Internals/StoreScp.cpp OrthancServer/OrthancInitialization.cpp + OrthancServer/OrthancPeerParameters.cpp OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/OrthancRestApi/OrthancRestArchive.cpp diff -r 566a2fb3c1fb -r 2d9a000aa3a6 OrthancServer/OrthancInitialization.cpp --- a/OrthancServer/OrthancInitialization.cpp Wed May 07 15:54:23 2014 +0200 +++ b/OrthancServer/OrthancInitialization.cpp Wed May 07 16:30:47 2014 +0200 @@ -293,38 +293,7 @@ throw OrthancException(ErrorCode_BadFileFormat); } - std::string url; - - try - { - url = modalities[name].get(0u, "").asString(); - - if (modalities[name].size() == 1) - { - peer.SetUsername(""); - peer.SetPassword(""); - } - else if (modalities[name].size() == 3) - { - peer.SetUsername(modalities[name].get(1u, "").asString()); - peer.SetPassword(modalities[name].get(2u, "").asString()); - } - else - { - throw OrthancException(ErrorCode_BadFileFormat); - } - } - catch (...) - { - throw OrthancException(ErrorCode_BadFileFormat); - } - - if (url.size() != 0 && url[url.size() - 1] != '/') - { - url += '/'; - } - - peer.SetUrl(url); + peer.FromJson(modalities[name]); } catch (OrthancException& e) { @@ -597,4 +566,46 @@ modalities.removeMember(symbolicName.c_str()); } + + + void UpdatePeer(const OrthancPeerParameters& peer) + { + boost::mutex::scoped_lock lock(globalMutex_); + + if (!configuration_->isMember("OrthancPeers")) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + Json::Value& peers = (*configuration_) ["OrthancPeers"]; + if (peers.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + peers.removeMember(peer.GetName().c_str()); + + Json::Value v; + peer.ToJson(v); + peers[peer.GetName()] = v; + } + + + void RemovePeer(const std::string& symbolicName) + { + boost::mutex::scoped_lock lock(globalMutex_); + + if (!configuration_->isMember("OrthancPeers")) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + Json::Value& peers = (*configuration_) ["OrthancPeers"]; + if (peers.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + peers.removeMember(symbolicName.c_str()); + } } diff -r 566a2fb3c1fb -r 2d9a000aa3a6 OrthancServer/OrthancInitialization.h --- a/OrthancServer/OrthancInitialization.h Wed May 07 15:54:23 2014 +0200 +++ b/OrthancServer/OrthancInitialization.h Wed May 07 16:30:47 2014 +0200 @@ -39,64 +39,10 @@ #include "../Core/HttpServer/MongooseServer.h" #include "DicomProtocol/RemoteModalityParameters.h" #include "ServerEnumerations.h" +#include "OrthancPeerParameters.h" namespace Orthanc { - class OrthancPeerParameters - { - private: - std::string name_; - std::string url_; - std::string username_; - std::string password_; - - public: - OrthancPeerParameters() : url_("http://localhost:8042/") - { - } - - const std::string& GetName() const - { - return name_; - } - - void SetName(const std::string& name) - { - name_ = name; - } - - const std::string& GetUrl() const - { - return url_; - } - - void SetUrl(const std::string& url) - { - url_ = url; - } - - const std::string& GetUsername() const - { - return username_; - } - - void SetUsername(const std::string& username) - { - username_ = username; - } - - const std::string& GetPassword() const - { - return password_; - } - - void SetPassword(const std::string& password) - { - password_ = password; - } - }; - - void OrthancInitialize(const char* configurationFile = NULL); void OrthancFinalize(); @@ -145,4 +91,8 @@ void UpdateModality(const RemoteModalityParameters& modality); void RemoveModality(const std::string& symbolicName); + + void UpdatePeer(const OrthancPeerParameters& peer); + + void RemovePeer(const std::string& symbolicName); } diff -r 566a2fb3c1fb -r 2d9a000aa3a6 OrthancServer/OrthancPeerParameters.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/OrthancPeerParameters.cpp Wed May 07 16:30:47 2014 +0200 @@ -0,0 +1,95 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + **/ + + +#include "OrthancPeerParameters.h" + +#include "../Core/OrthancException.h" + +namespace Orthanc +{ + OrthancPeerParameters::OrthancPeerParameters() : + url_("http://localhost:8042/") + { + } + + + void OrthancPeerParameters::FromJson(const Json::Value& peer) + { + if (!peer.isArray() || + (peer.size() != 1 && peer.size() != 3)) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + std::string url; + + try + { + url = peer.get(0u, "").asString(); + + if (peer.size() == 1) + { + SetUsername(""); + SetPassword(""); + } + else if (peer.size() == 3) + { + SetUsername(peer.get(1u, "").asString()); + SetPassword(peer.get(2u, "").asString()); + } + else + { + throw OrthancException(ErrorCode_BadFileFormat); + } + } + catch (...) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + if (url.size() != 0 && url[url.size() - 1] != '/') + { + url += '/'; + } + + SetUrl(url); + } + + + void OrthancPeerParameters::ToJson(Json::Value& value) const + { + value = Json::arrayValue; + value.append(GetUrl()); + value.append(GetUsername()); + value.append(GetPassword()); + } +} diff -r 566a2fb3c1fb -r 2d9a000aa3a6 OrthancServer/OrthancPeerParameters.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OrthancServer/OrthancPeerParameters.h Wed May 07 16:30:47 2014 +0200 @@ -0,0 +1,95 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + **/ + + +#pragma once + +#include +#include + +namespace Orthanc +{ + class OrthancPeerParameters + { + private: + std::string name_; + std::string url_; + std::string username_; + std::string password_; + + public: + OrthancPeerParameters(); + + const std::string& GetName() const + { + return name_; + } + + void SetName(const std::string& name) + { + name_ = name; + } + + const std::string& GetUrl() const + { + return url_; + } + + void SetUrl(const std::string& url) + { + url_ = url; + } + + const std::string& GetUsername() const + { + return username_; + } + + void SetUsername(const std::string& username) + { + username_ = username; + } + + const std::string& GetPassword() const + { + return password_; + } + + void SetPassword(const std::string& password) + { + password_ = password; + } + + void FromJson(const Json::Value& peer); + + void ToJson(Json::Value& value) const; + }; +} diff -r 566a2fb3c1fb -r 2d9a000aa3a6 OrthancServer/OrthancRestApi/OrthancRestModalities.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 15:54:23 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Wed May 07 16:30:47 2014 +0200 @@ -484,6 +484,26 @@ } + static void UpdatePeer(RestApi::PutCall& call) + { + Json::Value json; + Json::Reader reader; + if (reader.parse(call.GetPutBody(), json)) + { + OrthancPeerParameters peer; + peer.FromJson(json); + peer.SetName(call.GetUriComponent("id", "")); + UpdatePeer(peer); + } + } + + + static void DeletePeer(RestApi::DeleteCall& call) + { + RemovePeer(call.GetUriComponent("id", "")); + } + + void OrthancRestApi::RegisterModalities() { Register("/modalities", ListModalities); @@ -499,7 +519,8 @@ Register("/peers", ListPeers); Register("/peers/{id}", ListPeerOperations); + Register("/peers/{id}", UpdatePeer); + Register("/peers/{id}", DeletePeer); Register("/peers/{id}/store", PeerStore); - } }