changeset 3401:962e5f00744b

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Jun 2019 14:58:27 +0200
parents 0faae6f6e3c5
children cf31b5bacce3
files Core/HttpServer/EmbeddedResourceHttpHandler.cpp Core/HttpServer/EmbeddedResourceHttpHandler.h Core/HttpServer/FilesystemHttpHandler.cpp Core/HttpServer/FilesystemHttpHandler.h Core/HttpServer/HttpToolbox.cpp Core/HttpServer/HttpToolbox.h Core/HttpServer/IHttpHandler.h Core/RestApi/RestApi.cpp Core/RestApi/RestApi.h Core/RestApi/RestApiCall.cpp Core/RestApi/RestApiCall.h Core/RestApi/RestApiPostCall.h Core/RestApi/RestApiPutCall.h Core/Toolbox.cpp Core/Toolbox.h OrthancServer/OrthancHttpHandler.cpp OrthancServer/OrthancHttpHandler.h OrthancServer/OrthancRestApi/OrthancRestApi.cpp OrthancServer/OrthancRestApi/OrthancRestApi.h OrthancServer/OrthancRestApi/OrthancRestModalities.cpp OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h Plugins/Include/orthanc/OrthancCPlugin.h
diffstat 24 files changed, 71 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/EmbeddedResourceHttpHandler.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -62,7 +62,7 @@
     const UriComponents& uri,
     const Arguments& headers,
     const GetArguments& arguments,
-    const char* /*bodyData*/,
+    const void* /*bodyData*/,
     size_t /*bodySize*/)
   {
     if (!Toolbox::IsChildUri(baseUri_, uri))
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/EmbeddedResourceHttpHandler.h	Fri Jun 07 14:58:27 2019 +0200
@@ -70,7 +70,7 @@
       const UriComponents& uri,
       const Arguments& headers,
       const GetArguments& arguments,
-      const char* /*bodyData*/,
+      const void* /*bodyData*/,
       size_t /*bodySize*/);
   };
 }
--- a/Core/HttpServer/FilesystemHttpHandler.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/FilesystemHttpHandler.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -137,7 +137,7 @@
     const UriComponents& uri,
     const Arguments& headers,
     const GetArguments& arguments,
-    const char* /*bodyData*/,
+    const void* /*bodyData*/,
     size_t /*bodySize*/)
   {
     if (!Toolbox::IsChildUri(pimpl_->baseUri_, uri))
--- a/Core/HttpServer/FilesystemHttpHandler.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/FilesystemHttpHandler.h	Fri Jun 07 14:58:27 2019 +0200
@@ -72,7 +72,7 @@
       const UriComponents& uri,
       const Arguments& headers,
       const GetArguments& arguments,
-      const char* /*bodyData*/,
+      const void* /*bodyData*/,
       size_t /*bodySize*/);
 
     bool IsListDirectoryContent() const
--- a/Core/HttpServer/HttpToolbox.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/HttpToolbox.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -240,7 +240,7 @@
                               RequestOrigin origin,
                               HttpMethod method,
                               const std::string& uri,
-                              const char* bodyData,
+                              const void* bodyData,
                               size_t bodySize)
   {
     IHttpHandler::Arguments headers;  // No HTTP header
@@ -269,7 +269,7 @@
                                IHttpHandler& handler,
                                RequestOrigin origin,
                                const std::string& uri,
-                               const char* bodyData,
+                               const void* bodyData,
                                size_t bodySize)
   {
     return SimplePostOrPut(result, handler, origin, HttpMethod_Post, uri, bodyData, bodySize);
@@ -280,7 +280,7 @@
                               IHttpHandler& handler,
                               RequestOrigin origin,
                               const std::string& uri,
-                              const char* bodyData,
+                              const void* bodyData,
                               size_t bodySize)
   {
     return SimplePostOrPut(result, handler, origin, HttpMethod_Put, uri, bodyData, bodySize);
--- a/Core/HttpServer/HttpToolbox.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/HttpToolbox.h	Fri Jun 07 14:58:27 2019 +0200
@@ -76,14 +76,14 @@
                            IHttpHandler& handler,
                            RequestOrigin origin,
                            const std::string& uri,
-                           const char* bodyData,
+                           const void* bodyData,
                            size_t bodySize);
 
     static bool SimplePut(std::string& result,
                           IHttpHandler& handler,
                           RequestOrigin origin,
                           const std::string& uri,
-                          const char* bodyData,
+                          const void* bodyData,
                           size_t bodySize);
 
     static bool SimpleDelete(IHttpHandler& handler,
--- a/Core/HttpServer/IHttpHandler.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/HttpServer/IHttpHandler.h	Fri Jun 07 14:58:27 2019 +0200
@@ -85,7 +85,7 @@
                         const UriComponents& uri,
                         const Arguments& headers,
                         const GetArguments& getArguments,
-                        const char* bodyData,
+                        const void* bodyData,
                         size_t bodySize) = 0;
   };
 }
--- a/Core/RestApi/RestApi.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApi.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -55,7 +55,7 @@
       HttpMethod method_;
       const IHttpHandler::Arguments& headers_;
       const IHttpHandler::Arguments& getArguments_;
-      const char* bodyData_;
+      const void* bodyData_;
       size_t bodySize_;
 
     public:
@@ -67,7 +67,7 @@
                          HttpMethod method,
                          const IHttpHandler::Arguments& headers,
                          const IHttpHandler::Arguments& getArguments,
-                         const char* bodyData,
+                         const void* bodyData,
                          size_t bodySize) :
         api_(api),
         output_(output),
@@ -181,7 +181,7 @@
                        const UriComponents& uri,
                        const Arguments& headers,
                        const GetArguments& getArguments,
-                       const char* bodyData,
+                       const void* bodyData,
                        size_t bodySize)
   {
     RestApiOutput wrappedOutput(output, method);
--- a/Core/RestApi/RestApi.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApi.h	Fri Jun 07 14:58:27 2019 +0200
@@ -65,7 +65,7 @@
                         const UriComponents& uri,
                         const Arguments& headers,
                         const GetArguments& getArguments,
-                        const char* bodyData,
+                        const void* bodyData,
                         size_t bodySize);
 
     void Register(const std::string& path,
--- a/Core/RestApi/RestApiCall.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApiCall.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -37,11 +37,13 @@
 namespace Orthanc
 {
   bool RestApiCall::ParseJsonRequestInternal(Json::Value& result,
-                                             const char* request)
+                                             const void* body,
+                                             size_t size)
   {
     result.clear();
     Json::Reader reader;
-    return reader.parse(request, result);
+    return reader.parse(reinterpret_cast<const char*>(body),
+                        reinterpret_cast<const char*>(body) + size, result);
   }
 
 
--- a/Core/RestApi/RestApiCall.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApiCall.h	Fri Jun 07 14:58:27 2019 +0200
@@ -59,7 +59,8 @@
 
   protected:
     static bool ParseJsonRequestInternal(Json::Value& result,
-                                         const char* request);
+                                         const void* body,
+                                         size_t size);
 
   public:
     RestApiCall(RestApiOutput& output,
--- a/Core/RestApi/RestApiPostCall.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApiPostCall.h	Fri Jun 07 14:58:27 2019 +0200
@@ -40,7 +40,7 @@
   class RestApiPostCall : public RestApiCall
   {
   private:
-    const char* bodyData_;
+    const void* bodyData_;
     size_t bodySize_;
 
   public:
@@ -55,7 +55,7 @@
                     const IHttpHandler::Arguments& uriComponents,
                     const UriComponents& trailing,
                     const UriComponents& fullUri,
-                    const char* bodyData,
+                    const void* bodyData,
                     size_t bodySize) :
       RestApiCall(output, context, origin, remoteIp, username, 
                   httpHeaders, uriComponents, trailing, fullUri),
@@ -64,7 +64,7 @@
     {
     }
 
-    const char* GetBodyData() const
+    const void* GetBodyData() const
     {
       return bodyData_;
     }
@@ -76,12 +76,12 @@
 
     void BodyToString(std::string& result) const
     {
-      result.assign(bodyData_, bodySize_);
+      result.assign(reinterpret_cast<const char*>(bodyData_), bodySize_);
     }
 
     virtual bool ParseJsonRequest(Json::Value& result) const
     {
-      return ParseJsonRequestInternal(result, bodyData_);
-    }      
+      return ParseJsonRequestInternal(result, reinterpret_cast<const char*>(bodyData_), bodySize_);
+    }
   };
 }
--- a/Core/RestApi/RestApiPutCall.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/RestApi/RestApiPutCall.h	Fri Jun 07 14:58:27 2019 +0200
@@ -40,7 +40,7 @@
   class RestApiPutCall : public RestApiCall
   {
   private:
-    const char* bodyData_;
+    const void* bodyData_;
     size_t bodySize_;
 
   public:
@@ -55,7 +55,7 @@
                    const IHttpHandler::Arguments& uriComponents,
                    const UriComponents& trailing,
                    const UriComponents& fullUri,
-                   const char* bodyData,
+                   const void* bodyData,
                    size_t bodySize) :
       RestApiCall(output, context, origin, remoteIp, username,
                   httpHeaders, uriComponents, trailing, fullUri),
@@ -64,7 +64,7 @@
     {
     }
 
-    const char* GetBodyData() const
+    const void* GetBodyData() const
     {
       return bodyData_;
     }
@@ -76,12 +76,12 @@
 
     void BodyToString(std::string& result) const
     {
-      result.assign(bodyData_, bodySize_);
+      result.assign(reinterpret_cast<const char*>(bodyData_), bodySize_);
     }
 
     virtual bool ParseJsonRequest(Json::Value& result) const
     {
-      return ParseJsonRequestInternal(result, bodyData_);
+      return ParseJsonRequestInternal(result, reinterpret_cast<const char*>(bodyData_), bodySize_);
     }      
   };
 }
--- a/Core/Toolbox.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/Toolbox.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -745,7 +745,7 @@
   }
 
 
-  bool Toolbox::IsSHA1(const char* str,
+  bool Toolbox::IsSHA1(const void* str,
                        size_t size)
   {
     if (size == 0)
@@ -753,8 +753,8 @@
       return false;
     }
 
-    const char* start = str;
-    const char* end = str + size;
+    const char* start = reinterpret_cast<const char*>(str);
+    const char* end = start + size;
 
     // Trim the beginning of the string
     while (start < end)
--- a/Core/Toolbox.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Core/Toolbox.h	Fri Jun 07 14:58:27 2019 +0200
@@ -140,7 +140,7 @@
                      const void* data,
                      size_t size);
 
-    bool IsSHA1(const char* str,
+    bool IsSHA1(const void* str,
                 size_t size);
 
     bool IsSHA1(const std::string& s);
--- a/OrthancServer/OrthancHttpHandler.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancHttpHandler.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -69,7 +69,7 @@
                                   const UriComponents& uri,
                                   const Arguments& headers,
                                   const GetArguments& getArguments,
-                                  const char* bodyData,
+                                  const void* bodyData,
                                   size_t bodySize)
   {
     for (Handlers::const_iterator it = handlers_.begin(); it != handlers_.end(); ++it) 
--- a/OrthancServer/OrthancHttpHandler.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancHttpHandler.h	Fri Jun 07 14:58:27 2019 +0200
@@ -65,7 +65,7 @@
                         const UriComponents& uri,
                         const Arguments& headers,
                         const GetArguments& getArguments,
-                        const char* bodyData,
+                        const void* bodyData,
                         size_t bodySize);
 
     void Register(IHttpHandler& handler,
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -118,7 +118,8 @@
     LOG(INFO) << "Receiving a DICOM file of " << call.GetBodySize() << " bytes through HTTP";
 
     // TODO Remove unneccessary memcpy
-    std::string postData(call.GetBodyData(), call.GetBodySize());
+    std::string postData;
+    call.BodyToString(postData);
 
     DicomInstanceToStore toStore;
     toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
@@ -168,7 +169,7 @@
                               const UriComponents& uri,
                               const Arguments& headers,
                               const GetArguments& getArguments,
-                              const char* bodyData,
+                              const void* bodyData,
                               size_t bodySize)
   {
     MetricsRegistry::Timer timer(context_.GetMetricsRegistry(), "orthanc_rest_api_duration_ms");
--- a/OrthancServer/OrthancRestApi/OrthancRestApi.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestApi.h	Fri Jun 07 14:58:27 2019 +0200
@@ -85,7 +85,7 @@
                         const UriComponents& uri,
                         const Arguments& headers,
                         const GetArguments& getArguments,
-                        const char* bodyData,
+                        const void* bodyData,
                         size_t bodySize) ORTHANC_OVERRIDE;
 
     const bool& LeaveBarrierFlag() const
--- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -102,13 +102,11 @@
    ***************************************************************************/
 
   static bool MergeQueryAndTemplate(DicomMap& result,
-                                    const char* postData,
-                                    size_t postSize)
+                                    const RestApiCall& call)
   {
     Json::Value query;
-    Json::Reader reader;
 
-    if (!reader.parse(postData, postData + postSize, query) ||
+    if (!call.ParseJsonRequest(query) ||
         query.type() != Json::objectValue)
     {
       return false;
@@ -190,7 +188,7 @@
 
     DicomMap fields;
     DicomMap::SetupFindPatientTemplate(fields);
-    if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
+    if (!MergeQueryAndTemplate(fields, call))
     {
       return;
     }
@@ -219,7 +217,7 @@
 
     DicomMap fields;
     DicomMap::SetupFindStudyTemplate(fields);
-    if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
+    if (!MergeQueryAndTemplate(fields, call))
     {
       return;
     }
@@ -254,7 +252,7 @@
 
     DicomMap fields;
     DicomMap::SetupFindSeriesTemplate(fields);
-    if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
+    if (!MergeQueryAndTemplate(fields, call))
     {
       return;
     }
@@ -290,7 +288,7 @@
 
     DicomMap fields;
     DicomMap::SetupFindInstanceTemplate(fields);
-    if (!MergeQueryAndTemplate(fields, call.GetBodyData(), call.GetBodySize()))
+    if (!MergeQueryAndTemplate(fields, call))
     {
       return;
     }
@@ -340,7 +338,7 @@
 
     DicomMap m;
     DicomMap::SetupFindPatientTemplate(m);
-    if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
+    if (!MergeQueryAndTemplate(m, call))
     {
       return;
     }
@@ -363,7 +361,7 @@
       patients.ToJson(patient, i, true);
 
       DicomMap::SetupFindStudyTemplate(m);
-      if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
+      if (!MergeQueryAndTemplate(m, call))
       {
         return;
       }
@@ -382,7 +380,7 @@
         studies.ToJson(study, j, true);
 
         DicomMap::SetupFindSeriesTemplate(m);
-        if (!MergeQueryAndTemplate(m, call.GetBodyData(), call.GetBodySize()))
+        if (!MergeQueryAndTemplate(m, call))
         {
           return;
         }
@@ -1169,8 +1167,7 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     Json::Value json;
-    Json::Reader reader;
-    if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
+    if (call.ParseJsonRequest(json))
     {
       RemoteModalityParameters modality;
       modality.Unserialize(json);
@@ -1207,8 +1204,7 @@
     ServerContext& context = OrthancRestApi::GetContext(call);
 
     Json::Value json;
-    Json::Reader reader;
-    if (reader.parse(call.GetBodyData(), call.GetBodyData() + call.GetBodySize(), json))
+    if (call.ParseJsonRequest(json))
     {
       WebServiceParameters peer;
       peer.Unserialize(json);
--- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -174,7 +174,10 @@
 
   static void SetDefaultEncoding(RestApiPutCall& call)
   {
-    Encoding encoding = StringToEncoding(call.GetBodyData());
+    std::string body;
+    call.BodyToString(body);
+
+    Encoding encoding = StringToEncoding(body.c_str());
 
     {
       OrthancConfiguration::WriterLock lock;
@@ -453,7 +456,8 @@
   {
     bool enabled;
 
-    std::string body(call.GetBodyData());
+    std::string body;
+    call.BodyToString(body);
 
     if (body == "1")
     {
--- a/Plugins/Engine/OrthancPlugins.cpp	Fri Jun 07 14:26:09 2019 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Fri Jun 07 14:58:27 2019 +0200
@@ -1291,7 +1291,7 @@
                               const UriComponents& uri,
                               const Arguments& headers,
                               const GetArguments& getArguments,
-                              const char* bodyData,
+                              const void* bodyData,
                               size_t bodySize)
   {
     RestCallbackMatcher matcher(uri);
@@ -2387,7 +2387,7 @@
     if (p.method == OrthancPluginHttpMethod_Post ||
         p.method == OrthancPluginHttpMethod_Put)
     {
-      client.GetBody().assign(p.body, p.bodySize);
+      client.GetBody().assign(reinterpret_cast<const char*>(p.body), p.bodySize);
     }
     
     SetupHttpClient(client, p);
@@ -2480,12 +2480,12 @@
 
       case OrthancPluginHttpMethod_Post:
         client.SetMethod(HttpMethod_Post);
-        client.GetBody().assign(p.body, p.bodySize);
+        client.GetBody().assign(reinterpret_cast<const char*>(p.body), p.bodySize);
         break;
 
       case OrthancPluginHttpMethod_Put:
         client.SetMethod(HttpMethod_Put);
-        client.GetBody().assign(p.body, p.bodySize);
+        client.GetBody().assign(reinterpret_cast<const char*>(p.body), p.bodySize);
         break;
 
       case OrthancPluginHttpMethod_Delete:
--- a/Plugins/Engine/OrthancPlugins.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Plugins/Engine/OrthancPlugins.h	Fri Jun 07 14:58:27 2019 +0200
@@ -226,7 +226,7 @@
                         const UriComponents& uri,
                         const Arguments& headers,
                         const GetArguments& getArguments,
-                        const char* bodyData,
+                        const void* bodyData,
                         size_t bodySize);
 
     virtual bool InvokeService(SharedLibrary& plugin,
--- a/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Jun 07 14:26:09 2019 +0200
+++ b/Plugins/Include/orthanc/OrthancCPlugin.h	Fri Jun 07 14:58:27 2019 +0200
@@ -363,7 +363,7 @@
     /**
      * @brief For a PUT or POST request, the content of the body.
      **/
-    const char*             body;
+    const void*             body;
 
     /**
      * @brief For a PUT or POST request, the number of bytes of the body.
@@ -4032,7 +4032,7 @@
     const char*                 url;
     const char*                 username;
     const char*                 password;
-    const char*                 body;
+    const void*                 body;
     uint32_t                    bodySize;
   } _OrthancPluginCallHttpClient;
 
@@ -4093,7 +4093,7 @@
     OrthancPluginContext*       context,
     OrthancPluginMemoryBuffer*  target,
     const char*                 url,
-    const char*                 body,
+    const void*                 body,
     uint32_t                    bodySize,
     const char*                 username,
     const char*                 password)
@@ -4134,7 +4134,7 @@
     OrthancPluginContext*       context,
     OrthancPluginMemoryBuffer*  target,
     const char*                 url,
-    const char*                 body,
+    const void*                 body,
     uint32_t                    bodySize,
     const char*                 username,
     const char*                 password)
@@ -5485,7 +5485,7 @@
     uint32_t                    headersCount;
     const char* const*          headersKeys;
     const char* const*          headersValues;
-    const char*                 body;
+    const void*                 body;
     uint32_t                    bodySize;
     const char*                 username;
     const char*                 password;
@@ -5546,7 +5546,7 @@
     uint32_t                    headersCount,
     const char* const*          headersKeys,
     const char* const*          headersValues,
-    const char*                 body,
+    const void*                 body,
     uint32_t                    bodySize,
     const char*                 username,
     const char*                 password,
@@ -6295,7 +6295,7 @@
     uint32_t                    additionalHeadersCount;
     const char* const*          additionalHeadersKeys;
     const char* const*          additionalHeadersValues;
-    const char*                 body;
+    const void*                 body;
     uint32_t                    bodySize;
     uint32_t                    timeout;
   } _OrthancPluginCallPeerApi;
@@ -6347,7 +6347,7 @@
     uint32_t                    additionalHeadersCount,
     const char* const*          additionalHeadersKeys,
     const char* const*          additionalHeadersValues,
-    const char*                 body,
+    const void*                 body,
     uint32_t                    bodySize,
     uint32_t                    timeout)
   {