# HG changeset patch # User am@osimis.io # Date 1544098200 -3600 # Node ID 5947aeedf41f6158f9934e6cf719d42d36ad97ef # Parent e62e296a5714bff5cbf602af36345778eb529e41 added C++ plugin helpers diff -r e62e296a5714 -r 5947aeedf41f Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Dec 06 11:16:23 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Dec 06 13:10:00 2018 +0100 @@ -1123,6 +1123,16 @@ OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); } + void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) + { + OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); + } + + void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) + { + OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); + } + bool RestApiGetString(std::string& result, const std::string& uri, bool applyPlugins) diff -r e62e296a5714 -r 5947aeedf41f Plugins/Samples/Common/OrthancPluginCppWrapper.h --- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Dec 06 11:16:23 2018 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Dec 06 13:10:00 2018 +0100 @@ -20,7 +20,7 @@ * 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 @@ -48,10 +48,10 @@ #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE) #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \ (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \ - (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ - (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ - (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ - ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) + (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \ + (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \ + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision)))) #endif @@ -205,12 +205,12 @@ bool HttpGet(const std::string& url, const std::string& username, const std::string& password); - + bool HttpPost(const std::string& url, const std::string& body, const std::string& username, const std::string& password); - + bool HttpPut(const std::string& url, const std::string& body, const std::string& username, @@ -444,7 +444,7 @@ const std::string& body, bool applyPlugins) { - return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(), + return RestApiPost(result, uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins); } @@ -473,7 +473,7 @@ const std::string& body, bool applyPlugins) { - return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(), + return RestApiPut(result, uri, body.empty() ? NULL : body.c_str(), body.size(), applyPlugins); } @@ -485,8 +485,12 @@ const std::string& password); void AnswerJson(const Json::Value& value, - OrthancPluginRestOutput* output - ); + OrthancPluginRestOutput* output); + + void AnswerHttpError(uint16_t httpError, + OrthancPluginRestOutput* output); + + void AnswerMethodNotAllowed(OrthancPluginRestOutput* output, const char* allowedMethods); const char* GetMimeType(const std::string& path); @@ -528,7 +532,7 @@ // error message. This is to avoid duplicating the details, // because "OrthancException" already does it on construction. OrthancPluginSetHttpErrorDetails - (GetGlobalContext(), output, e.GetDetails(), false); + (GetGlobalContext(), output, e.GetDetails(), false); } #endif @@ -553,12 +557,12 @@ if (isThreadSafe) { OrthancPluginRegisterRestCallbackNoLock - (GetGlobalContext(), uri.c_str(), Internals::Protect); + (GetGlobalContext(), uri.c_str(), Internals::Protect); } else { OrthancPluginRegisterRestCallback - (GetGlobalContext(), uri.c_str(), Internals::Protect); + (GetGlobalContext(), uri.c_str(), Internals::Protect); } } @@ -623,11 +627,11 @@ bool DoGet(Json::Value& target, size_t index, const std::string& uri) const; - + bool DoGet(Json::Value& target, const std::string& name, const std::string& uri) const; - + bool DoPost(MemoryBuffer& target, size_t index, const std::string& uri, @@ -642,7 +646,7 @@ size_t index, const std::string& uri, const std::string& body) const; - + bool DoPost(Json::Value& target, const std::string& name, const std::string& uri,