# HG changeset patch # User am@osimis.io # Date 1544023828 -3600 # Node ID e361df74639fa817b826983bd7947d694eda93c5 # Parent 146eaed9b02ce57dd5657eba88920daf06f124cc added few plugin helpers diff -r 146eaed9b02c -r e361df74639f Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Dec 05 16:30:11 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Wed Dec 05 16:30:28 2018 +0100 @@ -1113,6 +1113,32 @@ #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output + ) + { + Json::StyledWriter writer; + std::string bodyString = writer.write(value); + + OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); + } + + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins) + { + MemoryBuffer answer; + if (!answer.RestApiGet(uri, applyPlugins)) + { + return false; + } + else + { + answer.ToString(result); + return true; + } + } + bool RestApiGet(Json::Value& result, const std::string& uri, @@ -1311,6 +1337,58 @@ } } + const char* GetMimeType(const std::string& path) + { + size_t dot = path.find_last_of('.'); + + std::string extension = (dot == std::string::npos) ? "" : path.substr(dot); + std::transform(extension.begin(), extension.end(), extension.begin(), tolower); + + if (extension == ".html") + { + return "text/html"; + } + else if (extension == ".css") + { + return "text/css"; + } + else if (extension == ".js") + { + return "application/javascript"; + } + else if (extension == ".gif") + { + return "image/gif"; + } + else if (extension == ".svg") + { + return "image/svg+xml"; + } + else if (extension == ".json") + { + return "application/json"; + } + else if (extension == ".xml") + { + return "application/xml"; + } + else if (extension == ".wasm") + { + return "application/wasm"; + } + else if (extension == ".png") + { + return "image/png"; + } + else if (extension == ".jpg" || extension == ".jpeg") + { + return "image/jpeg"; + } + else + { + return "application/octet-stream"; + } + } diff -r 146eaed9b02c -r e361df74639f Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Dec 05 16:30:11 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Wed Dec 05 16:30:28 2018 +0100 @@ -419,6 +419,10 @@ const std::string& uri, bool applyPlugins); + bool RestApiGetString(std::string& result, + const std::string& uri, + bool applyPlugins); + bool RestApiPost(Json::Value& result, const std::string& uri, const char* body, @@ -466,6 +470,13 @@ const std::string& username, const std::string& password); + void AnswerJson(const Json::Value& value, + OrthancPluginRestOutput* output + ); + + const char* GetMimeType(const std::string& path); + + void LogError(const std::string& message); void LogWarning(const std::string& message);