# HG changeset patch # User amazy # Date 1512477176 -3600 # Node ID 2ddecfba10c00162924e4ede277f19ed0792323e # Parent e97bacbeeffe162fe182e7b338ebbda1fa42a0ca added ?expand to /servers route diff -r e97bacbeeffe -r 2ddecfba10c0 NEWS --- 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) ======================== diff -r e97bacbeeffe -r 2ddecfba10c0 Plugin/Plugin.cpp --- 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 servers; OrthancPlugins::DicomWebServers::GetInstance().ListServers(servers); - Json::Value json = Json::arrayValue; - for (std::list::const_iterator it = servers.begin(); it != servers.end(); ++it) + if (RequestHasKey(request, "expand")) { - json.append(*it); - } + Json::Value result = Json::objectValue; + for (std::list::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::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)