annotate Core/RestApi/RestApi.h @ 841:89a593f66104 jpeg

fix windows build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Jun 2014 20:37:35 +0200
parents 2d0a347e8cfc
children 7e8cde5905fd 83622b0f544c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
689
2d0a347e8cfc switch to 2014
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 659
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * In addition, as a special exception, the copyright holders of this
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * program give permission to link the code of its release with the
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * the linked executables. You must obey the GNU General Public License
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * you do not wish to do so, delete this exception statement from your
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * version. If you delete this exception statement from all source files
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * in the program, then also delete it here.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #pragma once
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "../HttpServer/HttpHandler.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "RestApiPath.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "RestApiOutput.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
217
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
39 #include <list>
1ac3aacd10a5 simplifications
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 216
diff changeset
40
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace Orthanc
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 class RestApi : public HttpHandler
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
45 public:
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
46 class Call
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 private:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
51 RestApiOutput& output_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
52 RestApi& context_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
53 const HttpHandler::Arguments& httpHeaders_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
54 const RestApiPath::Components& uriComponents_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
55 const UriComponents& trailing_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
56 const UriComponents& fullUri_;
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
57
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
58 Call(RestApiOutput& output,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
59 RestApi& context,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
60 const HttpHandler::Arguments& httpHeaders,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
61 const RestApiPath::Components& uriComponents,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
62 const UriComponents& trailing,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
63 const UriComponents& fullUri) :
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
64 output_(output),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
65 context_(context),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
66 httpHeaders_(httpHeaders),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
67 uriComponents_(uriComponents),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
68 trailing_(trailing),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
69 fullUri_(fullUri)
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
70 {
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
71 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
73 protected:
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
74 static bool ParseJsonRequestInternal(Json::Value& result,
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
75 const char* request);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
76
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 RestApiOutput& GetOutput()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
80 return output_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
83 RestApi& GetContext()
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
85 return context_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
215
c07170f3f4f7 refactoring of access to images in REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
88 const UriComponents& GetFullUri() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
90 return fullUri_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
92
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
93 const UriComponents& GetTrailingUri() const
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
94 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
95 return trailing_;
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 237
diff changeset
96 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 std::string GetUriComponent(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
99 const std::string& defaultValue) const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
101 return HttpHandler::GetArgument(uriComponents_, name, defaultValue);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
103
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
104 std::string GetHttpHeader(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
105 const std::string& defaultValue) const
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
106 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
107 return HttpHandler::GetArgument(httpHeaders_, name, defaultValue);
212
f276b175dcaf delete resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
108 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
109
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 331
diff changeset
110 const HttpHandler::Arguments& GetHttpHeaders() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 331
diff changeset
111 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
112 return httpHeaders_;
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 331
diff changeset
113 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 331
diff changeset
114
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
115 void ParseCookies(HttpHandler::Arguments& result) const
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
116 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
117 HttpHandler::ParseCookies(result, httpHeaders_);
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
118 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
119
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
120 virtual bool ParseJsonRequest(Json::Value& result) const = 0;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
124 class GetCall : public Call
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 private:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
129 const HttpHandler::Arguments& getArguments_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 public:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
132 GetCall(RestApiOutput& output,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
133 RestApi& context,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
134 const HttpHandler::Arguments& httpHeaders,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
135 const RestApiPath::Components& uriComponents,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
136 const UriComponents& trailing,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
137 const UriComponents& fullUri,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
138 const HttpHandler::Arguments& getArguments) :
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
139 Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
140 getArguments_(getArguments)
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
141 {
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
142 }
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
143
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 std::string GetArgument(const std::string& name,
231
8098448bd827 export log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 217
diff changeset
145 const std::string& defaultValue) const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
147 return HttpHandler::GetArgument(getArguments_, name, defaultValue);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
149
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
150 bool HasArgument(const std::string& name) const
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
151 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
152 return getArguments_.find(name) != getArguments_.end();
237
16a4ac70bd8a last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 231
diff changeset
153 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
154
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
155 virtual bool ParseJsonRequest(Json::Value& result) const;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
158
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
159 class PutCall : public Call
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 private:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
164 const std::string& data_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 public:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
167 PutCall(RestApiOutput& output,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
168 RestApi& context,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
169 const HttpHandler::Arguments& httpHeaders,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
170 const RestApiPath::Components& uriComponents,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
171 const UriComponents& trailing,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
172 const UriComponents& fullUri,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
173 const std::string& data) :
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
174 Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
175 data_(data)
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
176 {
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
177 }
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
178
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
179 const std::string& GetPutBody() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
181 return data_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
183
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
184 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
185 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
186 return ParseJsonRequestInternal(result, GetPutBody().c_str());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
187 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
190 class PostCall : public Call
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 friend class RestApi;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 private:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
195 const std::string& data_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 public:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
198 PostCall(RestApiOutput& output,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
199 RestApi& context,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
200 const HttpHandler::Arguments& httpHeaders,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
201 const RestApiPath::Components& uriComponents,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
202 const UriComponents& trailing,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
203 const UriComponents& fullUri,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
204 const std::string& data) :
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
205 Call(output, context, httpHeaders, uriComponents, trailing, fullUri),
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
206 data_(data)
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
207 {
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
208 }
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
209
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
210 const std::string& GetPostBody() const
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
212 return data_;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
214
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
215 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
216 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
217 return ParseJsonRequestInternal(result, GetPostBody().c_str());
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
218 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
221 class DeleteCall : public Call
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
223 public:
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
224 DeleteCall(RestApiOutput& output,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
225 RestApi& context,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
226 const HttpHandler::Arguments& httpHeaders,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
227 const RestApiPath::Components& uriComponents,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
228 const UriComponents& trailing,
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
229 const UriComponents& fullUri) :
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
230 Call(output, context, httpHeaders, uriComponents, trailing, fullUri)
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
231 {
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
232 }
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
233
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
234 virtual bool ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
235 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
236 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
237 return true;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
238 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 typedef void (*GetHandler) (GetCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 typedef void (*DeleteHandler) (DeleteCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 typedef void (*PutHandler) (PutCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 typedef void (*PostHandler) (PostCall& call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 private:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 typedef std::list< std::pair<RestApiPath*, GetHandler> > GetHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 typedef std::list< std::pair<RestApiPath*, PutHandler> > PutHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 typedef std::list< std::pair<RestApiPath*, PostHandler> > PostHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 typedef std::list< std::pair<RestApiPath*, DeleteHandler> > DeleteHandlers;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 GetHandlers getHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 PutHandlers putHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 PostHandlers postHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 DeleteHandlers deleteHandlers_;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 bool IsGetAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 bool IsPutAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 bool IsPostAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 bool IsDeleteAccepted(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 std::string GetAcceptedMethods(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 public:
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 RestApi()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ~RestApi();
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 virtual bool IsServedUri(const UriComponents& uri);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 virtual void Handle(HttpOutput& output,
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
277 HttpMethod method,
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 const UriComponents& uri,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 const Arguments& headers,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 const Arguments& getArguments,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 const std::string& postData);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 GetHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 PutHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 PostHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 void Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 DeleteHandler handler);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 };
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }