Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.cpp @ 976:6968356679c0 plugins
integration mainline->plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 30 Jun 2014 14:55:43 +0200 |
parents | 7d88f3f4a3b3 c550e99c452b |
children | 2a9e08136860 |
comparison
equal
deleted
inserted
replaced
973:ab6475e33473 | 976:6968356679c0 |
---|---|
36 #include <stdlib.h> // To define "_exit()" under Windows | 36 #include <stdlib.h> // To define "_exit()" under Windows |
37 #include <glog/logging.h> | 37 #include <glog/logging.h> |
38 | 38 |
39 namespace Orthanc | 39 namespace Orthanc |
40 { | 40 { |
41 bool RestApi::Call::ParseJsonRequestInternal(Json::Value& result, | |
42 const char* request) | |
43 { | |
44 result.clear(); | |
45 Json::Reader reader; | |
46 return reader.parse(request, result); | |
47 } | |
48 | |
49 | |
50 bool RestApi::GetCall::ParseJsonRequest(Json::Value& result) const | |
51 { | |
52 result.clear(); | |
53 | |
54 for (HttpHandler::Arguments::const_iterator | |
55 it = getArguments_.begin(); it != getArguments_.end(); ++it) | |
56 { | |
57 result[it->first] = it->second; | |
58 } | |
59 | |
60 return true; | |
61 } | |
62 | |
63 | |
64 bool RestApi::IsGetAccepted(const UriComponents& uri) | 41 bool RestApi::IsGetAccepted(const UriComponents& uri) |
65 { | 42 { |
66 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 43 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
67 it != getHandlers_.end(); ++it) | 44 it != getHandlers_.end(); ++it) |
68 { | 45 { |
190 } | 167 } |
191 | 168 |
192 | 169 |
193 bool ok = false; | 170 bool ok = false; |
194 RestApiOutput restOutput(output); | 171 RestApiOutput restOutput(output); |
195 RestApiPath::Components components; | 172 HttpHandler::Arguments components; |
196 UriComponents trailing; | 173 UriComponents trailing; |
197 | 174 |
198 if (method == HttpMethod_Get) | 175 if (method == HttpMethod_Get) |
199 { | 176 { |
200 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 177 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
202 { | 179 { |
203 if (it->first->Match(components, trailing, uri)) | 180 if (it->first->Match(components, trailing, uri)) |
204 { | 181 { |
205 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); | 182 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); |
206 ok = true; | 183 ok = true; |
207 GetCall call(restOutput, *this, headers, components, trailing, uri, getArguments); | 184 RestApiGetCall call(restOutput, *this, headers, components, trailing, uri, getArguments); |
208 it->second(call); | 185 it->second(call); |
209 } | 186 } |
210 } | 187 } |
211 } | 188 } |
212 else if (method == HttpMethod_Put) | 189 else if (method == HttpMethod_Put) |
216 { | 193 { |
217 if (it->first->Match(components, trailing, uri)) | 194 if (it->first->Match(components, trailing, uri)) |
218 { | 195 { |
219 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); | 196 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); |
220 ok = true; | 197 ok = true; |
221 PutCall call(restOutput, *this, headers, components, trailing, uri, postData); | 198 RestApiPutCall call(restOutput, *this, headers, components, trailing, uri, postData); |
222 it->second(call); | 199 it->second(call); |
223 } | 200 } |
224 } | 201 } |
225 } | 202 } |
226 else if (method == HttpMethod_Post) | 203 else if (method == HttpMethod_Post) |
230 { | 207 { |
231 if (it->first->Match(components, trailing, uri)) | 208 if (it->first->Match(components, trailing, uri)) |
232 { | 209 { |
233 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); | 210 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); |
234 ok = true; | 211 ok = true; |
235 PostCall call(restOutput, *this, headers, components, trailing, uri, postData); | 212 RestApiPostCall call(restOutput, *this, headers, components, trailing, uri, postData); |
236 it->second(call); | 213 it->second(call); |
237 } | 214 } |
238 } | 215 } |
239 } | 216 } |
240 else if (method == HttpMethod_Delete) | 217 else if (method == HttpMethod_Delete) |
244 { | 221 { |
245 if (it->first->Match(components, trailing, uri)) | 222 if (it->first->Match(components, trailing, uri)) |
246 { | 223 { |
247 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); | 224 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); |
248 ok = true; | 225 ok = true; |
249 DeleteCall call(restOutput, *this, headers, components, trailing, uri); | 226 RestApiDeleteCall call(restOutput, *this, headers, components, trailing, uri); |
250 it->second(call); | 227 it->second(call); |
251 } | 228 } |
252 } | 229 } |
253 } | 230 } |
254 | 231 |
261 | 238 |
262 return true; | 239 return true; |
263 } | 240 } |
264 | 241 |
265 void RestApi::Register(const std::string& path, | 242 void RestApi::Register(const std::string& path, |
266 GetHandler handler) | 243 RestApiGetCall::Handler handler) |
267 { | 244 { |
268 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 245 getHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
269 } | 246 } |
270 | 247 |
271 void RestApi::Register(const std::string& path, | 248 void RestApi::Register(const std::string& path, |
272 PutHandler handler) | 249 RestApiPutCall::Handler handler) |
273 { | 250 { |
274 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 251 putHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
275 } | 252 } |
276 | 253 |
277 void RestApi::Register(const std::string& path, | 254 void RestApi::Register(const std::string& path, |
278 PostHandler handler) | 255 RestApiPostCall::Handler handler) |
279 { | 256 { |
280 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 257 postHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
281 } | 258 } |
282 | 259 |
283 void RestApi::Register(const std::string& path, | 260 void RestApi::Register(const std::string& path, |
284 DeleteHandler handler) | 261 RestApiDeleteCall::Handler handler) |
285 { | 262 { |
286 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); | 263 deleteHandlers_.push_back(std::make_pair(new RestApiPath(path), handler)); |
287 } | 264 } |
288 } | 265 } |