annotate Core/RestApi/RestApi.cpp @ 1000:13e230bbd882 lua-scripting

rename filter to command
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 04 Jul 2014 14:14:14 +0200
parents c550e99c452b
children 6968356679c0
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 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 bool RestApi::IsGetAccepted(const UriComponents& uri)
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 for (GetHandlers::const_iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
44 it != getHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 if (it->first->Match(uri))
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 return true;
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 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 bool RestApi::IsPutAccepted(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 for (PutHandlers::const_iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
58 it != putHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 return true;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
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 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
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 bool RestApi::IsPostAccepted(const UriComponents& 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 for (PostHandlers::const_iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
72 it != postHandlers_.end(); ++it)
209
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 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 return true;
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 }
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 return false;
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 bool RestApi::IsDeleteAccepted(const UriComponents& 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 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
86 it != deleteHandlers_.end(); ++it)
209
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 if (it->first->Match(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return true;
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 }
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 return false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
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 static void AddMethod(std::string& target,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 const std::string& method)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (target.size() > 0)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 target += "," + method;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 else
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 target = method;
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 std::string RestApi::GetAcceptedMethods(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 std::string s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 if (IsGetAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 AddMethod(s, "GET");
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 if (IsPutAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 AddMethod(s, "PUT");
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 if (IsPostAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 AddMethod(s, "POST");
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 if (IsDeleteAccepted(uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 AddMethod(s, "DELETE");
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 return s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 RestApi::~RestApi()
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 for (GetHandlers::iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
128 it != getHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
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 for (PutHandlers::iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
134 it != putHandlers_.end(); ++it)
209
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 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
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 for (PostHandlers::iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
140 it != postHandlers_.end(); ++it)
209
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 delete it->first;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
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 for (DeleteHandlers::iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
146 it != deleteHandlers_.end(); ++it)
209
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 delete it->first;
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 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 bool RestApi::IsServedUri(const UriComponents& uri)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 return (IsGetAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 IsPutAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 IsPostAccepted(uri) ||
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 IsDeleteAccepted(uri));
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 void RestApi::Handle(HttpOutput& output,
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
161 HttpMethod method,
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 const UriComponents& uri,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 const Arguments& headers,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 const Arguments& getArguments,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 const std::string& postData)
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 bool ok = false;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 RestApiOutput restOutput(output);
975
c550e99c452b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 974
diff changeset
169 HttpHandler::Arguments components;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 UriComponents trailing;
210
96b7918a6a18 start of the refactoring of the Orthanc REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 209
diff changeset
171
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
172 if (method == HttpMethod_Get)
209
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 for (GetHandlers::const_iterator it = getHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
175 it != getHandlers_.end(); ++it)
209
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 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
179 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 ok = true;
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
181 RestApiGetCall call(restOutput, *this, headers, components, trailing, uri, getArguments);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
186 else if (method == HttpMethod_Put)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 for (PutHandlers::const_iterator it = putHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
189 it != putHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
193 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ok = true;
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
195 RestApiPutCall call(restOutput, *this, headers, components, trailing, uri, postData);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
200 else if (method == HttpMethod_Post)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 for (PostHandlers::const_iterator it = postHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
203 it != postHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
207 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ok = true;
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
209 RestApiPostCall call(restOutput, *this, headers, components, trailing, uri, postData);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 }
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
214 else if (method == HttpMethod_Delete)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin();
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 477
diff changeset
217 it != deleteHandlers_.end(); ++it)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 if (it->first->Match(components, trailing, uri))
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 {
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
221 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 ok = true;
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
223 RestApiDeleteCall call(restOutput, *this, headers, components, trailing, uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 it->second(call);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (!ok)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 {
477
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
231 LOG(INFO) << "REST method " << EnumerationToString(method)
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
232 << " not allowed on: " << Toolbox::FlattenUri(uri);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 output.SendMethodNotAllowedError(GetAcceptedMethods(uri));
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
238 RestApiGetCall::Handler handler)
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 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
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
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
244 RestApiPutCall::Handler handler)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
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 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
250 RestApiPostCall::Handler handler)
209
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 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 }
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 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
256 RestApiDeleteCall::Handler handler)
209
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 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler));
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 }