Mercurial > hg > orthanc-dicomweb
changeset 199:2ddecfba10c0
added ?expand to /servers route
author | amazy |
---|---|
date | Tue, 05 Dec 2017 13:32:56 +0100 |
parents | e97bacbeeffe |
children | fa93e7147ebf |
files | NEWS Plugin/Plugin.cpp |
diffstat | 2 files changed, 39 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Thu Aug 24 15:10:13 2017 +0200 +++ b/NEWS Tue Dec 05 13:32:56 2017 +0100 @@ -2,7 +2,7 @@ =============================== * Support for OpenBSD - +* added ?expand argument to /servers route Version 0.4 (2017-07-19) ========================
--- a/Plugin/Plugin.cpp Thu Aug 24 15:10:13 2017 +0200 +++ b/Plugin/Plugin.cpp Tue Dec 05 13:32:56 2017 +0100 @@ -87,6 +87,16 @@ } } +bool RequestHasKey(const OrthancPluginHttpRequest* request, const char* key) +{ + for (uint32_t i = 0; i < request->getCount; i++) + { + if (strcmp(key, request->getKeys[i]) == 0) + return true; + } + return false; +} + void ListServers(OrthancPluginRestOutput* output, const char* url, @@ -103,18 +113,39 @@ std::list<std::string> servers; OrthancPlugins::DicomWebServers::GetInstance().ListServers(servers); - Json::Value json = Json::arrayValue; - for (std::list<std::string>::const_iterator it = servers.begin(); it != servers.end(); ++it) + if (RequestHasKey(request, "expand")) { - json.append(*it); - } + Json::Value result = Json::objectValue; + for (std::list<std::string>::const_iterator it = servers.begin(); it != servers.end(); ++it) + { + Orthanc::WebServiceParameters server = OrthancPlugins::DicomWebServers::GetInstance().GetServer(*it); + Json::Value jsonServer; + // only return the minimum information to identify the destination, do not include "security" information like passwords + jsonServer["Url"] = server.GetUrl(); + if (!server.GetUsername().empty()) + { + jsonServer["Username"] = server.GetUsername(); + } + result[*it] = jsonServer; + } - std::string answer = json.toStyledString(); - OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), "application/json"); + std::string answer = result.toStyledString(); + OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), "application/json"); + } + else // if expand is not present, keep backward compatibility and return an array of server names + { + Json::Value json = Json::arrayValue; + for (std::list<std::string>::const_iterator it = servers.begin(); it != servers.end(); ++it) + { + json.append(*it); + } + + std::string answer = json.toStyledString(); + OrthancPluginAnswerBuffer(context, output, answer.c_str(), answer.size(), "application/json"); + } } } - void ListServerOperations(OrthancPluginRestOutput* output, const char* /*url*/, const OrthancPluginHttpRequest* request)