annotate OrthancFramework/Sources/RestApi/RestApiHierarchy.cpp @ 5853:4d932683049d get-scu tip

very first implementation of C-Get SCU
author Alain Mazy <am@orthanc.team>
date Tue, 29 Oct 2024 17:25:49 +0100
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1624
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * 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
10 * 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
11 * 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
12 * the License, or (at your option) any later version.
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * 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
17 * Lesser General Public License for more details.
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1624
0a2ad4a6858f fix missing precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1444
diff changeset
25 #include "../PrecompiledHeaders.h"
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "RestApiHierarchy.h"
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
975
c550e99c452b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
28 #include "../OrthancException.h"
c550e99c452b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
29
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <cassert>
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
31 #include <stdio.h>
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace Orthanc
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
35 RestApiHierarchy::Resource::Resource() :
972
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
36 getHandler_(NULL),
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
37 postHandler_(NULL),
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
38 putHandler_(NULL),
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
39 deleteHandler_(NULL)
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
40 {
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
41 }
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
42
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
43
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
44 bool RestApiHierarchy::Resource::HasHandler(HttpMethod method) const
972
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
45 {
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
46 switch (method)
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
47 {
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
48 case HttpMethod_Get:
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
49 return getHandler_ != NULL;
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
50
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
51 case HttpMethod_Post:
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
52 return postHandler_ != NULL;
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
53
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
54 case HttpMethod_Put:
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
55 return putHandler_ != NULL;
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
56
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
57 case HttpMethod_Delete:
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
58 return deleteHandler_ != NULL;
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
59
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
60 default:
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
61 throw OrthancException(ErrorCode_ParameterOutOfRange);
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
62 }
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
63 }
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
64
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
65
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
66 void RestApiHierarchy::Resource::Register(RestApiGetCall::Handler handler)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
67 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
68 getHandler_ = handler;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
69 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
70
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
71 void RestApiHierarchy::Resource::Register(RestApiPutCall::Handler handler)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
72 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
73 putHandler_ = handler;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
74 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
75
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
76 void RestApiHierarchy::Resource::Register(RestApiPostCall::Handler handler)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
77 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
78 postHandler_ = handler;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
79 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
80
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
81 void RestApiHierarchy::Resource::Register(RestApiDeleteCall::Handler handler)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
82 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
83 deleteHandler_ = handler;
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
84 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
85
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
86
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
87 bool RestApiHierarchy::Resource::IsEmpty() const
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
972
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
89 return (getHandler_ == NULL &&
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
90 postHandler_ == NULL &&
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
91 putHandler_ == NULL &&
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
92 deleteHandler_ == NULL);
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
93 }
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
94
2047e6f033bd refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 970
diff changeset
95
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 RestApiHierarchy& RestApiHierarchy::AddChild(Children& children,
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 const std::string& name)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 Children::iterator it = children.find(name);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 if (it == children.end())
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 // Create new child
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 RestApiHierarchy *child = new RestApiHierarchy;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 children[name] = child;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return *child;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 else
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 return *it->second;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
115
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
116 bool RestApiHierarchy::Resource::Handle(RestApiGetCall& call) const
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
117 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
118 if (getHandler_ != NULL)
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
119 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
120 getHandler_(call);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
121 return true;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
122 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
123 else
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
124 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
125 return false;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
126 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
127 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
128
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
129
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
130 bool RestApiHierarchy::Resource::Handle(RestApiPutCall& call) const
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
131 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
132 if (putHandler_ != NULL)
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
133 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
134 putHandler_(call);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
135 return true;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
136 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
137 else
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
138 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
139 return false;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
140 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
141 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
142
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
143
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
144 bool RestApiHierarchy::Resource::Handle(RestApiPostCall& call) const
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
145 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
146 if (postHandler_ != NULL)
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
147 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
148 postHandler_(call);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
149 return true;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
150 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
151 else
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
152 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
153 return false;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
154 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
155 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
156
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
157
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
158 bool RestApiHierarchy::Resource::Handle(RestApiDeleteCall& call) const
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
159 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
160 if (deleteHandler_ != NULL)
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
161 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
162 deleteHandler_(call);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
163 return true;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
164 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
165 else
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
166 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
167 return false;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
168 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
169 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
170
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
171
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 void RestApiHierarchy::DeleteChildren(Children& children)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 for (Children::iterator it = children.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
175 it != children.end(); ++it)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 delete it->second;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 template <typename Handler>
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 void RestApiHierarchy::RegisterInternal(const RestApiPath& path,
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 Handler handler,
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 size_t level)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if (path.GetLevelCount() == level)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 if (path.IsUniversalTrailing())
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
191 handlersWithTrailing_.Register(handler);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 else
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 handlers_.Register(handler);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 else
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 RestApiHierarchy* child;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 if (path.IsWildcardLevel(level))
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 child = &AddChild(wildcardChildren_, path.GetWildcardName(level));
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 else
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 child = &AddChild(children_, path.GetLevelName(level));
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 child->RegisterInternal(path, handler, level + 1);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
215 bool RestApiHierarchy::LookupResource(HttpToolbox::Arguments& components,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
216 const UriComponents& uri,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
217 IVisitor& visitor,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
218 size_t level)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
220 if (uri.size() != 0 &&
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
221 level > uri.size())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
222 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
223 return false;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
224 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
225
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 // Look for an exact match on the resource of interest
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
227 if (uri.size() == 0 ||
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
228 level == uri.size())
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
230 UriComponents noTrailing;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
231
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 if (!handlers_.IsEmpty() &&
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
233 visitor.Visit(handlers_, uri, false, components, noTrailing))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 return true;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
240 if (level < uri.size()) // A recursive call is possible
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
242 // Try and go down in the hierarchy, using an exact match for the child
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
243 Children::const_iterator child = children_.find(uri[level]);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
244 if (child != children_.end())
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
246 if (child->second->LookupResource(components, uri, visitor, level + 1))
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
247 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
248 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
249 }
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
252 // Try and go down in the hierarchy, using wildcard rules for children
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
253 for (child = wildcardChildren_.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
254 child != wildcardChildren_.end(); ++child)
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
255 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
256 HttpToolbox::Arguments subComponents = components;
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
257 subComponents[child->first] = uri[level];
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
259 if (child->second->LookupResource(subComponents, uri, visitor, level + 1))
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
260 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
261 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
262 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
263 }
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 // As a last resort, call the universal handlers, if any
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
268 if (!handlersWithTrailing_.IsEmpty())
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
270 UriComponents trailing;
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 trailing.resize(uri.size() - level);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 size_t pos = 0;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 for (size_t i = level; i < uri.size(); i++, pos++)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 trailing[pos] = uri[i];
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 assert(pos == trailing.size());
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
280 if (visitor.Visit(handlersWithTrailing_, uri, true, components, trailing))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 return true;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 return false;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
290 bool RestApiHierarchy::CanGenerateDirectory() const
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
291 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
292 return (handlersWithTrailing_.IsEmpty() &&
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
293 wildcardChildren_.empty());
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
294 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
295
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
296
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 bool RestApiHierarchy::GetDirectory(Json::Value& result,
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 const UriComponents& uri,
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 size_t level)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 if (uri.size() == level)
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
303 if (CanGenerateDirectory())
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 result = Json::arrayValue;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 for (Children::const_iterator it = children_.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
308 it != children_.end(); ++it)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 result.append(it->first);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 return true;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 else
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 return false;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 Children::const_iterator child = children_.find(uri[level]);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 if (child != children_.end())
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 if (child->second->GetDirectory(result, uri, level + 1))
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 return true;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 for (child = wildcardChildren_.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
331 child != wildcardChildren_.end(); ++child)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 if (child->second->GetDirectory(result, uri, level + 1))
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 return true;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 return false;
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 RestApiHierarchy::~RestApiHierarchy()
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 DeleteChildren(children_);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 DeleteChildren(wildcardChildren_);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
349 void RestApiHierarchy::Register(const std::string& uri,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 972
diff changeset
350 RestApiGetCall::Handler handler)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 {
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
352 RestApiPath path(uri);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 RegisterInternal(path, handler, 0);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
356 void RestApiHierarchy::Register(const std::string& uri,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 972
diff changeset
357 RestApiPutCall::Handler handler)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 {
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
359 RestApiPath path(uri);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 RegisterInternal(path, handler, 0);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
363 void RestApiHierarchy::Register(const std::string& uri,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 972
diff changeset
364 RestApiPostCall::Handler handler)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
366 RestApiPath path(uri);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 RegisterInternal(path, handler, 0);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
370 void RestApiHierarchy::Register(const std::string& uri,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 972
diff changeset
371 RestApiDeleteCall::Handler handler)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
970
1a3817d84f39 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 969
diff changeset
373 RestApiPath path(uri);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 RegisterInternal(path, handler, 0);
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 void RestApiHierarchy::CreateSiteMap(Json::Value& target) const
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
379 target = Json::objectValue;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
380
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
381 /*std::string s = " ";
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
382 if (handlers_.HasHandler(HttpMethod_Get))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
384 s += "GET ";
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
387 if (handlers_.HasHandler(HttpMethod_Post))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
389 s += "POST ";
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
392 if (handlers_.HasHandler(HttpMethod_Put))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
394 s += "PUT ";
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
397 if (handlers_.HasHandler(HttpMethod_Delete))
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
399 s += "DELETE ";
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
402 target = s;*/
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
403
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
404 for (Children::const_iterator it = children_.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
405 it != children_.end(); ++it)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
407 it->second->CreateSiteMap(target[it->first]);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
410 for (Children::const_iterator it = wildcardChildren_.begin();
1303
bba8a47922d1 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
411 it != wildcardChildren_.end(); ++it)
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
412 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
413 it->second->CreateSiteMap(target["<" + it->first + ">"]);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 978
diff changeset
414 }
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
417 bool RestApiHierarchy::GetDirectory(Json::Value &result, const UriComponents &uri)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
418 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
419 return GetDirectory(result, uri, 0);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
420 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
421
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
422
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
423 bool RestApiHierarchy::LookupResource(const UriComponents& uri,
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
424 IVisitor& visitor)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
426 HttpToolbox::Arguments components;
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
427 return LookupResource(components, uri, visitor, 0);
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 }
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
430
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
431
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
432 namespace
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
433 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
434 // Anonymous namespace to avoid clashes between compilation modules
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
435
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
436 class AcceptedMethodsVisitor : public RestApiHierarchy::IVisitor
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
437 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
438 private:
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
439 std::set<HttpMethod>& methods_;
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
440
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
441 public:
4203
4d42408da117 improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
442 explicit AcceptedMethodsVisitor(std::set<HttpMethod>& methods) :
4d42408da117 improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
443 methods_(methods)
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
444 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
445 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
446
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
447 virtual bool Visit(const RestApiHierarchy::Resource& resource,
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
448 const UriComponents& uri,
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
449 bool hasTrailing,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
450 const HttpToolbox::Arguments& components,
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
451 const UriComponents& trailing)
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
452 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
453 if (!hasTrailing) // Ignore universal handlers
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
454 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
455 if (resource.HasHandler(HttpMethod_Get))
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
456 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
457 methods_.insert(HttpMethod_Get);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
458 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
459
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
460 if (resource.HasHandler(HttpMethod_Post))
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
461 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
462 methods_.insert(HttpMethod_Post);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
463 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
464
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
465 if (resource.HasHandler(HttpMethod_Put))
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
466 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
467 methods_.insert(HttpMethod_Put);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
468 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
469
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
470 if (resource.HasHandler(HttpMethod_Delete))
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
471 {
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
472 methods_.insert(HttpMethod_Delete);
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
473 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
474 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
475
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
476 return false; // Continue to check all the possible ways to access this URI
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
477 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
478 };
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
479 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
480
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
481 void RestApiHierarchy::GetAcceptedMethods(std::set<HttpMethod>& methods,
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
482 const UriComponents& uri)
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
484 HttpToolbox::Arguments components;
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
485 AcceptedMethodsVisitor visitor(methods);
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
486 if (LookupResource(components, uri, visitor, 0))
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
487 {
1444
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
488 Json::Value d;
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
489 if (GetDirectory(d, uri))
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
490 {
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
491 methods.insert(HttpMethod_Get);
b2b09a3dbd8e refactoring: OrthancHttpHandler inside OrthancServer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
492 }
978
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
493 }
ce3106e5843f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 975
diff changeset
494 }
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4203
diff changeset
495
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
496 void RestApiHierarchy::ExploreAllResources(IVisitor& visitor,
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
497 const UriComponents& path,
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
498 const std::set<std::string>& uriArguments) const
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
499 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
500 HttpToolbox::Arguments args;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
501
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
502 for (std::set<std::string>::const_iterator it = uriArguments.begin(); it != uriArguments.end(); ++it)
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
503 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
504 args[*it] = "";
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
505 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
506
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
507 if (!handlers_.IsEmpty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
508 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
509 visitor.Visit(handlers_, path, false, args, UriComponents());
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
510 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
511
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
512 if (!handlersWithTrailing_.IsEmpty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
513 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
514 visitor.Visit(handlersWithTrailing_, path, true, args, UriComponents());
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
515 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
516
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
517 for (Children::const_iterator
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
518 it = children_.begin(); it != children_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
519 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
520 assert(it->second != NULL);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
521 UriComponents c = path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
522 c.push_back(it->first);
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
523 it->second->ExploreAllResources(visitor, c, uriArguments);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
524 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
525
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
526 for (Children::const_iterator
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
527 it = wildcardChildren_.begin(); it != wildcardChildren_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
528 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
529 if (uriArguments.find(it->first) != uriArguments.end())
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
530 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
531 throw OrthancException(ErrorCode_InternalError, "Twice the same URI argument in a path: " + it->first);
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
532 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
533
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
534 std::set<std::string> d = uriArguments;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
535 d.insert(it->first);
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
536
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
537 assert(it->second != NULL);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
538 UriComponents c = path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
539 c.push_back("{" + it->first + "}");
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
540 it->second->ExploreAllResources(visitor, c, d);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
541 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
542 }
969
3dce528b0cc2 RestApiHierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }