# HG changeset patch # User Sebastien Jodogne # Date 1447423605 -3600 # Node ID 94990da8710e3017d9249ee4763afb08b2b9ee77 # Parent c24dac8c1d4ec46595d4a2968afc1d112f68ed5a OrthancPluginRestApiGet2 diff -r c24dac8c1d4e -r 94990da8710e Core/HttpServer/HttpToolbox.cpp --- a/Core/HttpServer/HttpToolbox.cpp Fri Nov 13 13:20:28 2015 +0100 +++ b/Core/HttpServer/HttpToolbox.cpp Fri Nov 13 15:06:45 2015 +0100 @@ -201,10 +201,9 @@ bool HttpToolbox::SimpleGet(std::string& result, IHttpHandler& handler, RequestOrigin origin, - const std::string& uri) + const std::string& uri, + const IHttpHandler::Arguments& httpHeaders) { - IHttpHandler::Arguments headers; // No HTTP header - UriComponents curi; IHttpHandler::GetArguments getArguments; ParseGetQuery(curi, getArguments, uri.c_str()); @@ -213,7 +212,7 @@ HttpOutput http(stream, false /* no keep alive */); if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Get, curi, - headers, getArguments, NULL /* no body for GET */, 0)) + httpHeaders, getArguments, NULL /* no body for GET */, 0)) { stream.GetOutput(result); return true; @@ -225,6 +224,16 @@ } + bool HttpToolbox::SimpleGet(std::string& result, + IHttpHandler& handler, + RequestOrigin origin, + const std::string& uri) + { + IHttpHandler::Arguments headers; // No HTTP header + return SimpleGet(result, handler, origin, uri, headers); + } + + static bool SimplePostOrPut(std::string& result, IHttpHandler& handler, RequestOrigin origin, diff -r c24dac8c1d4e -r 94990da8710e Core/HttpServer/HttpToolbox.h --- a/Core/HttpServer/HttpToolbox.h Fri Nov 13 13:20:28 2015 +0100 +++ b/Core/HttpServer/HttpToolbox.h Fri Nov 13 15:06:45 2015 +0100 @@ -65,6 +65,12 @@ RequestOrigin origin, const std::string& uri); + static bool SimpleGet(std::string& result, + IHttpHandler& handler, + RequestOrigin origin, + const std::string& uri, + const IHttpHandler::Arguments& httpHeaders); + static bool SimplePost(std::string& result, IHttpHandler& handler, RequestOrigin origin, diff -r c24dac8c1d4e -r 94990da8710e NEWS --- a/NEWS Fri Nov 13 13:20:28 2015 +0100 +++ b/NEWS Fri Nov 13 15:06:45 2015 +0100 @@ -19,8 +19,11 @@ * New function "OrthancPluginRegisterErrorCode()" to declare custom error codes * New function "OrthancPluginRegisterDictionaryTag()" to declare custom DICOM tags +* New function "OrthancPluginRestApiGet2()" to provide HTTP headers when calling Orthanc API * New "OrthancStarted", "OrthancStopped", "UpdatedAttachment" and "UpdatedMetadata" events in change callbacks +* "/system" URI gives information about the plugins used for storage area and DB back-end +* Plugin callbacks should now return explicit "OrthancPluginErrorCode" instead of integers Lua --- @@ -33,8 +36,6 @@ * Full refactoring of the searching features * C-Move SCP for studies using AccessionNumber tag * Fix issue 4 (C-Store Association not renegotiated on Specific-to-specific transfer syntax change) -* "/system" URI gives information about the plugins used for storage area and DB back-end -* Plugin callbacks should now return explicit "OrthancPluginErrorCode" instead of integers * "/tools/create-dicom" can create tags with unknown VR * "--logdir" flag creates a single log file instead of 3 separate files for errors/warnings/infos * "--errors" flag lists the error codes that could be returned by Orthanc diff -r c24dac8c1d4e -r 94990da8710e Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Fri Nov 13 13:20:28 2015 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Fri Nov 13 15:06:45 2015 +0100 @@ -819,6 +819,36 @@ } + void OrthancPlugins::RestApiGet2(const void* parameters) + { + const _OrthancPluginRestApiGet2& p = + *reinterpret_cast(parameters); + + LOG(INFO) << "Plugin making REST GET call on URI " << p.uri + << (p.afterPlugins ? " (after plugins)" : " (built-in API)"); + + IHttpHandler::Arguments headers; + + for (uint32_t i = 0; i < p.headersCount; i++) + { + headers[p.headersKeys[i]] = p.headersValues[i]; + } + + CheckContextAvailable(); + IHttpHandler& handler = pimpl_->context_->GetHttpHandler().RestrictToOrthancRestApi(!p.afterPlugins); + + std::string result; + if (HttpToolbox::SimpleGet(result, handler, RequestOrigin_Plugins, p.uri, headers)) + { + CopyToMemoryBuffer(*p.target, result); + } + else + { + throw OrthancException(ErrorCode_BadRequest); + } + } + + void OrthancPlugins::RestApiPostPut(bool isPost, const void* parameters, bool afterPlugins) @@ -1395,6 +1425,10 @@ RestApiGet(parameters, true); return true; + case _OrthancPluginService_RestApiGet2: + RestApiGet2(parameters); + return true; + case _OrthancPluginService_RestApiPost: RestApiPostPut(true, parameters, false); return true; diff -r c24dac8c1d4e -r 94990da8710e Plugins/Engine/OrthancPlugins.h --- a/Plugins/Engine/OrthancPlugins.h Fri Nov 13 13:20:28 2015 +0100 +++ b/Plugins/Engine/OrthancPlugins.h Fri Nov 13 15:06:45 2015 +0100 @@ -91,6 +91,8 @@ void RestApiGet(const void* parameters, bool afterPlugins); + void RestApiGet2(const void* parameters); + void RestApiPostPut(bool isPost, const void* parameters, bool afterPlugins); diff -r c24dac8c1d4e -r 94990da8710e Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Fri Nov 13 13:20:28 2015 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Fri Nov 13 15:06:45 2015 +0100 @@ -428,6 +428,7 @@ _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, _OrthancPluginService_RestApiPutAfterPlugins = 3013, _OrthancPluginService_ReconstructMainDicomTags = 3014, + _OrthancPluginService_RestApiGet2 = 3015, /* Access to DICOM instances */ _OrthancPluginService_GetInstanceRemoteAet = 4000, @@ -3974,6 +3975,55 @@ } + typedef struct + { + OrthancPluginMemoryBuffer* target; + const char* uri; + uint32_t headersCount; + const char* const* headersKeys; + const char* const* headersValues; + int32_t afterPlugins; + } _OrthancPluginRestApiGet2; + + /** + * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers. + * + * Make a GET call to the Orthanc REST API with extended + * parameters. The result to the query is stored into a newly + * allocated memory buffer. + * + * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). + * @param target The target memory buffer. + * @param uri The URI in the built-in Orthanc API. + * @param headersCount The number of HTTP headers. + * @param headersKeys Array containing the keys of the HTTP headers. + * @param headersValues Array containing the values of the HTTP headers. + * @param afterPlugins If 0, the built-in API of Orthanc is used. + * If 1, the API is tainted by the plugins. + * @return 0 if success, or the error code if failure. + * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins + * @ingroup Orthanc + **/ + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2( + OrthancPluginContext* context, + OrthancPluginMemoryBuffer* target, + const char* uri, + uint32_t headersCount, + const char* const* headersKeys, + const char* const* headersValues, + int32_t afterPlugins) + { + _OrthancPluginRestApiGet2 params; + params.target = target; + params.uri = uri; + params.headersCount = headersCount; + params.headersKeys = headersKeys; + params.headersValues = headersValues; + params.afterPlugins = afterPlugins; + + return context->InvokeService(context, _OrthancPluginService_RestApiGet2, ¶ms); + } + #ifdef __cplusplus } #endif diff -r c24dac8c1d4e -r 94990da8710e Plugins/Samples/Basic/Plugin.c --- a/Plugins/Samples/Basic/Plugin.c Fri Nov 13 13:20:28 2015 +0100 +++ b/Plugins/Samples/Basic/Plugin.c Fri Nov 13 15:06:45 2015 +0100 @@ -194,9 +194,7 @@ } else { - printf("ICI1\n"); error = OrthancPluginRestApiGetAfterPlugins(context, &tmp, request->groups[1]); - printf("ICI2\n"); } if (error)