# HG changeset patch # User Sebastien Jodogne # Date 1404132798 -7200 # Node ID c550e99c452b1094d2ff2246ea18ac2d11f6f25a # Parent 83622b0f544cd695c26c65e122df5ba845119395 refactoring diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApi.cpp --- a/Core/RestApi/RestApi.cpp Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApi.cpp Mon Jun 30 14:53:18 2014 +0200 @@ -166,7 +166,7 @@ { bool ok = false; RestApiOutput restOutput(output); - RestApiPath::Components components; + HttpHandler::Arguments components; UriComponents trailing; if (method == HttpMethod_Get) diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiCall.h --- a/Core/RestApi/RestApiCall.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiCall.h Mon Jun 30 14:53:18 2014 +0200 @@ -46,7 +46,7 @@ RestApiOutput& output_; RestApi& context_; const HttpHandler::Arguments& httpHeaders_; - const RestApiPath::Components& uriComponents_; + const HttpHandler::Arguments& uriComponents_; const UriComponents& trailing_; const UriComponents& fullUri_; @@ -58,7 +58,7 @@ RestApiCall(RestApiOutput& output, RestApi& context, const HttpHandler::Arguments& httpHeaders, - const RestApiPath::Components& uriComponents, + const HttpHandler::Arguments& uriComponents, const UriComponents& trailing, const UriComponents& fullUri) : output_(output), diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiDeleteCall.h --- a/Core/RestApi/RestApiDeleteCall.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiDeleteCall.h Mon Jun 30 14:53:18 2014 +0200 @@ -44,7 +44,7 @@ RestApiDeleteCall(RestApiOutput& output, RestApi& context, const HttpHandler::Arguments& httpHeaders, - const RestApiPath::Components& uriComponents, + const HttpHandler::Arguments& uriComponents, const UriComponents& trailing, const UriComponents& fullUri) : RestApiCall(output, context, httpHeaders, uriComponents, trailing, fullUri) diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiGetCall.h --- a/Core/RestApi/RestApiGetCall.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiGetCall.h Mon Jun 30 14:53:18 2014 +0200 @@ -47,7 +47,7 @@ RestApiGetCall(RestApiOutput& output, RestApi& context, const HttpHandler::Arguments& httpHeaders, - const RestApiPath::Components& uriComponents, + const HttpHandler::Arguments& uriComponents, const UriComponents& trailing, const UriComponents& fullUri, const HttpHandler::Arguments& getArguments) : diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiHierarchy.cpp --- a/Core/RestApi/RestApiHierarchy.cpp Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiHierarchy.cpp Mon Jun 30 14:53:18 2014 +0200 @@ -32,6 +32,8 @@ #include "RestApiHierarchy.h" +#include "../OrthancException.h" + #include namespace Orthanc @@ -163,7 +165,7 @@ } - bool RestApiHierarchy::LookupHandler(RestApiPath::Components& components, + bool RestApiHierarchy::LookupHandler(HttpHandler::Arguments& components, const UriComponents& uri, ResourceCallback callback, size_t level, @@ -198,7 +200,7 @@ for (child = wildcardChildren_.begin(); child != wildcardChildren_.end(); child++) { - RestApiPath::Components subComponents = components; + HttpHandler::Arguments subComponents = components; subComponents[child->first] = uri[level]; if (child->second->LookupHandler(components, uri, callback, level + 1, call)) @@ -280,7 +282,7 @@ bool RestApiHierarchy::GetCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call) { @@ -298,7 +300,7 @@ bool RestApiHierarchy::PostCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call) { @@ -316,7 +318,7 @@ bool RestApiHierarchy::PutCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call) { @@ -334,7 +336,7 @@ bool RestApiHierarchy::DeleteCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call) { @@ -432,28 +434,28 @@ bool RestApiHierarchy::Handle(RestApiGetCall& call, const UriComponents& uri) { - RestApiPath::Components components; + HttpHandler::Arguments components; return LookupHandler(components, uri, GetCallback, 0, &call); } bool RestApiHierarchy::Handle(RestApiPutCall& call, const UriComponents& uri) { - RestApiPath::Components components; + HttpHandler::Arguments components; return LookupHandler(components, uri, PutCallback, 0, &call); } bool RestApiHierarchy::Handle(RestApiPostCall& call, const UriComponents& uri) { - RestApiPath::Components components; + HttpHandler::Arguments components; return LookupHandler(components, uri, PostCallback, 0, &call); } bool RestApiHierarchy::Handle(RestApiDeleteCall& call, const UriComponents& uri) { - RestApiPath::Components components; + HttpHandler::Arguments components; return LookupHandler(components, uri, DeleteCallback, 0, &call); } diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiHierarchy.h --- a/Core/RestApi/RestApiHierarchy.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiHierarchy.h Mon Jun 30 14:53:18 2014 +0200 @@ -32,12 +32,10 @@ #pragma once -#include "RestApi.h" - -#include "../OrthancException.h" - -#include -#include +#include "RestApiGetCall.h" +#include "RestApiPostCall.h" +#include "RestApiPutCall.h" +#include "RestApiDeleteCall.h" namespace Orthanc { @@ -47,9 +45,9 @@ class Handlers { private: - RestApiGetCall::Handler getHandler_; - RestApiPostCall::Handler postHandler_; - RestApiPutCall::Handler putHandler_; + RestApiGetCall::Handler getHandler_; + RestApiPostCall::Handler postHandler_; + RestApiPutCall::Handler putHandler_; RestApiDeleteCall::Handler deleteHandler_; public: @@ -92,7 +90,7 @@ typedef std::map Children; typedef bool (*ResourceCallback) (Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call); @@ -112,7 +110,7 @@ Handler handler, size_t level); - bool LookupHandler(RestApiPath::Components& components, + bool LookupHandler(HttpHandler::Arguments& components, const UriComponents& uri, ResourceCallback callback, size_t level, @@ -124,25 +122,25 @@ static bool GetCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call); static bool PostCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call); static bool PutCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call); static bool DeleteCallback(Handlers& handlers, const UriComponents& uri, - const RestApiPath::Components& components, + const HttpHandler::Arguments& components, const UriComponents& trailing, void* call); diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiPath.cpp --- a/Core/RestApi/RestApiPath.cpp Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiPath.cpp Mon Jun 30 14:53:18 2014 +0200 @@ -78,7 +78,7 @@ } } - bool RestApiPath::Match(Components& components, + bool RestApiPath::Match(HttpHandler::Arguments& components, UriComponents& trailing, const std::string& uriRaw) const { @@ -87,7 +87,7 @@ return Match(components, trailing, uri); } - bool RestApiPath::Match(Components& components, + bool RestApiPath::Match(HttpHandler::Arguments& components, UriComponents& trailing, const UriComponents& uri) const { @@ -135,7 +135,7 @@ bool RestApiPath::Match(const UriComponents& uri) const { - Components components; + HttpHandler::Arguments components; UriComponents trailing; return Match(components, trailing, uri); } diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiPath.h --- a/Core/RestApi/RestApiPath.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiPath.h Mon Jun 30 14:53:18 2014 +0200 @@ -33,6 +33,8 @@ #pragma once #include "../Toolbox.h" +#include "../HttpServer/HttpHandler.h" + #include namespace Orthanc @@ -45,16 +47,14 @@ std::vector components_; public: - typedef std::map Components; - RestApiPath(const std::string& uri); // This version is slower - bool Match(Components& components, + bool Match(HttpHandler::Arguments& components, UriComponents& trailing, const std::string& uriRaw) const; - bool Match(Components& components, + bool Match(HttpHandler::Arguments& components, UriComponents& trailing, const UriComponents& uri) const; diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiPostCall.h --- a/Core/RestApi/RestApiPostCall.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiPostCall.h Mon Jun 30 14:53:18 2014 +0200 @@ -47,7 +47,7 @@ RestApiPostCall(RestApiOutput& output, RestApi& context, const HttpHandler::Arguments& httpHeaders, - const RestApiPath::Components& uriComponents, + const HttpHandler::Arguments& uriComponents, const UriComponents& trailing, const UriComponents& fullUri, const std::string& data) : diff -r 83622b0f544c -r c550e99c452b Core/RestApi/RestApiPutCall.h --- a/Core/RestApi/RestApiPutCall.h Mon Jun 30 14:44:05 2014 +0200 +++ b/Core/RestApi/RestApiPutCall.h Mon Jun 30 14:53:18 2014 +0200 @@ -47,7 +47,7 @@ RestApiPutCall(RestApiOutput& output, RestApi& context, const HttpHandler::Arguments& httpHeaders, - const RestApiPath::Components& uriComponents, + const HttpHandler::Arguments& uriComponents, const UriComponents& trailing, const UriComponents& fullUri, const std::string& data) : diff -r 83622b0f544c -r c550e99c452b UnitTestsSources/RestApiTests.cpp --- a/UnitTestsSources/RestApiTests.cpp Mon Jun 30 14:44:05 2014 +0200 +++ b/UnitTestsSources/RestApiTests.cpp Mon Jun 30 14:53:18 2014 +0200 @@ -122,7 +122,7 @@ TEST(RestApi, RestApiPath) { - RestApiPath::Components args; + HttpHandler::Arguments args; UriComponents trail; {