Mercurial > hg > orthanc
annotate OrthancFramework/Sources/RestApi/RestApiHierarchy.h @ 4151:8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 19 Aug 2020 11:59:02 +0200 |
parents | bf7b9edf6b81 |
children | b30a8de92ad9 |
rev | line source |
---|---|
969 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
978
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
969 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
969 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
969 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
969 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
975 | 25 #include "RestApiGetCall.h" |
26 #include "RestApiPostCall.h" | |
27 #include "RestApiPutCall.h" | |
28 #include "RestApiDeleteCall.h" | |
969 | 29 |
978 | 30 #include <set> |
31 | |
969 | 32 namespace Orthanc |
33 { | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
34 class ORTHANC_PUBLIC RestApiHierarchy : public boost::noncopyable |
969 | 35 { |
978 | 36 public: |
4026
05a363186da6
ORTHANC_BUILDING_FRAMEWORK_LIBRARY, Orthanc::InitializeFramework()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
37 class ORTHANC_PUBLIC Resource : public boost::noncopyable |
969 | 38 { |
972 | 39 private: |
975 | 40 RestApiGetCall::Handler getHandler_; |
41 RestApiPostCall::Handler postHandler_; | |
42 RestApiPutCall::Handler putHandler_; | |
974 | 43 RestApiDeleteCall::Handler deleteHandler_; |
969 | 44 |
972 | 45 public: |
978 | 46 Resource(); |
972 | 47 |
48 bool HasHandler(HttpMethod method) const; | |
969 | 49 |
974 | 50 void Register(RestApiGetCall::Handler handler) |
969 | 51 { |
972 | 52 getHandler_ = handler; |
969 | 53 } |
54 | |
974 | 55 void Register(RestApiPutCall::Handler handler) |
969 | 56 { |
972 | 57 putHandler_ = handler; |
969 | 58 } |
59 | |
974 | 60 void Register(RestApiPostCall::Handler handler) |
969 | 61 { |
972 | 62 postHandler_ = handler; |
969 | 63 } |
64 | |
974 | 65 void Register(RestApiDeleteCall::Handler handler) |
969 | 66 { |
972 | 67 deleteHandler_ = handler; |
969 | 68 } |
69 | |
70 bool IsEmpty() const; | |
978 | 71 |
72 bool Handle(RestApiGetCall& call) const; | |
73 | |
74 bool Handle(RestApiPutCall& call) const; | |
75 | |
76 bool Handle(RestApiPostCall& call) const; | |
77 | |
78 bool Handle(RestApiDeleteCall& call) const; | |
969 | 79 }; |
80 | |
81 | |
978 | 82 class IVisitor : public boost::noncopyable |
83 { | |
84 public: | |
85 virtual ~IVisitor() | |
86 { | |
87 } | |
88 | |
89 virtual bool Visit(const Resource& resource, | |
90 const UriComponents& uri, | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
91 const IHttpHandler::Arguments& components, |
978 | 92 const UriComponents& trailing) = 0; |
93 }; | |
94 | |
95 | |
96 private: | |
969 | 97 typedef std::map<std::string, RestApiHierarchy*> Children; |
98 | |
978 | 99 Resource handlers_; |
969 | 100 Children children_; |
101 Children wildcardChildren_; | |
978 | 102 Resource universalHandlers_; |
969 | 103 |
104 static RestApiHierarchy& AddChild(Children& children, | |
105 const std::string& name); | |
106 | |
107 static void DeleteChildren(Children& children); | |
108 | |
109 template <typename Handler> | |
110 void RegisterInternal(const RestApiPath& path, | |
111 Handler handler, | |
112 size_t level); | |
113 | |
978 | 114 bool CanGenerateDirectory() const; |
115 | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1288
diff
changeset
|
116 bool LookupResource(IHttpHandler::Arguments& components, |
978 | 117 const UriComponents& uri, |
118 IVisitor& visitor, | |
119 size_t level); | |
969 | 120 |
121 bool GetDirectory(Json::Value& result, | |
122 const UriComponents& uri, | |
123 size_t level); | |
124 | |
125 public: | |
126 ~RestApiHierarchy(); | |
127 | |
970 | 128 void Register(const std::string& uri, |
974 | 129 RestApiGetCall::Handler handler); |
969 | 130 |
970 | 131 void Register(const std::string& uri, |
974 | 132 RestApiPutCall::Handler handler); |
969 | 133 |
970 | 134 void Register(const std::string& uri, |
974 | 135 RestApiPostCall::Handler handler); |
969 | 136 |
970 | 137 void Register(const std::string& uri, |
974 | 138 RestApiDeleteCall::Handler handler); |
969 | 139 |
140 void CreateSiteMap(Json::Value& target) const; | |
141 | |
142 bool GetDirectory(Json::Value& result, | |
143 const UriComponents& uri) | |
144 { | |
145 return GetDirectory(result, uri, 0); | |
146 } | |
147 | |
978 | 148 bool LookupResource(const UriComponents& uri, |
149 IVisitor& visitor); | |
969 | 150 |
978 | 151 void GetAcceptedMethods(std::set<HttpMethod>& methods, |
152 const UriComponents& uri); | |
969 | 153 }; |
154 } |