annotate Core/RestApi/RestApi.cpp @ 871:923e919324b1 jpeg

integration mainline -> jpeg
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 11 Jun 2014 09:13:53 +0200
parents a811bdf8b8eb
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
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
33 #include "../PrecompiledHeaders.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "RestApi.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
36 #include <stdlib.h> // To define "_exit()" under Windows
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
37 #include <glog/logging.h>
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
38
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace Orthanc
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
331
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
41 bool RestApi::Call::ParseJsonRequestInternal(Json::Value& result,
5a96dac27959 base class for rest calls made public
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 304
diff changeset
42 const char* request)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
43 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
44 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
45 Json::Reader reader;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
46 return reader.parse(request, result);
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
47 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
48
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
49
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
50 bool RestApi::GetCall::ParseJsonRequest(Json::Value& result) const
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
51 {
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
52 result.clear();
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
53
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
54 for (HttpHandler::Arguments::const_iterator
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
55 it = getArguments_.begin(); it != getArguments_.end(); ++it)
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
56 {
335
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 331
diff changeset
57 result[it->first] = it->second;
304
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
58 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
59
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
60 return true;
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
61 }
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
62
4eea080e6e7a refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
63
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 bool RestApi::IsGetAccepted(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 for (GetHandlers::const_iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
67 it != getHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 return true;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 bool RestApi::IsPutAccepted(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 for (PutHandlers::const_iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
81 it != putHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 return true;
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 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 bool RestApi::IsPostAccepted(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 for (PostHandlers::const_iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
95 it != postHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return true;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 bool RestApi::IsDeleteAccepted(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
109 it != deleteHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return true;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 static void AddMethod(std::string& target,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 const std::string& method)
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 if (target.size() > 0)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 target += "," + method;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 else
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 target = method;
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string RestApi::GetAcceptedMethods(const UriComponents& uri)
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 std::string s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 if (IsGetAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 AddMethod(s, "GET");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 if (IsPutAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 AddMethod(s, "PUT");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 if (IsPostAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 AddMethod(s, "POST");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (IsDeleteAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 AddMethod(s, "DELETE");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 return s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 RestApi::~RestApi()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 for (GetHandlers::iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
151 it != getHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 for (PutHandlers::iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
157 it != putHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 delete it->first;
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 for (PostHandlers::iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
163 it != postHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 for (DeleteHandlers::iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
169 it != deleteHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 bool RestApi::IsServedUri(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 return (IsGetAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 IsPutAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 IsPostAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 IsDeleteAccepted(uri));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 void RestApi::Handle(HttpOutput& output,
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
184 HttpMethod method,
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 const UriComponents& uri,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 const Arguments& headers,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 const Arguments& getArguments,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 const std::string& postData)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 bool ok = false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 RestApiOutput restOutput(output);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 RestApiPath::Components components;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 UriComponents trailing;
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
194
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
195 if (method == HttpMethod_Get)
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 for (GetHandlers::const_iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
198 it != getHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
202 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ok = true;
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
204 GetCall call(restOutput, *this, headers, components, trailing, uri, getArguments);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
209 else if (method == HttpMethod_Put)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 for (PutHandlers::const_iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
212 it != putHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
216 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ok = true;
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
218 PutCall call(restOutput, *this, headers, components, trailing, uri, postData);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
223 else if (method == HttpMethod_Post)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 for (PostHandlers::const_iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
226 it != postHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
230 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 ok = true;
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
232 PostCall call(restOutput, *this, headers, components, trailing, uri, postData);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
237 else if (method == HttpMethod_Delete)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
240 it != deleteHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
244 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 ok = true;
659
443cced10836 code cleaning
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 656
diff changeset
246 DeleteCall call(restOutput, *this, headers, components, trailing, uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 it->second(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 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (!ok)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
477
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
254 LOG(INFO) << "REST method " << EnumerationToString(method)
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
255 << " not allowed on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 output.SendMethodNotAllowedError(GetAcceptedMethods(uri));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
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 void RestApi::Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 GetHandler handler)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 void RestApi::Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 PutHandler handler)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
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 void RestApi::Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 PostHandler handler)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 void RestApi::Register(const std::string& path,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 DeleteHandler handler)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
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 }