Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.cpp @ 759:8cfc6119a5bd dicom-rt
integration mainline -> dicom-rt
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Apr 2014 16:04:55 +0200 |
parents | 2d0a347e8cfc |
children | a811bdf8b8eb |
comparison
equal
deleted
inserted
replaced
605:b82292ba2083 | 759:8cfc6119a5bd |
---|---|
1 /** | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
4 * Belgium | 4 * Belgium |
5 * | 5 * |
6 * This program is free software: you can redistribute it and/or | 6 * This program is free software: you can redistribute it and/or |
7 * modify it under the terms of the GNU General Public License as | 7 * modify it under the terms of the GNU General Public License as |
8 * published by the Free Software Foundation, either version 3 of the | 8 * published by the Free Software Foundation, either version 3 of the |
49 bool RestApi::GetCall::ParseJsonRequest(Json::Value& result) const | 49 bool RestApi::GetCall::ParseJsonRequest(Json::Value& result) const |
50 { | 50 { |
51 result.clear(); | 51 result.clear(); |
52 | 52 |
53 for (HttpHandler::Arguments::const_iterator | 53 for (HttpHandler::Arguments::const_iterator |
54 it = getArguments_->begin(); it != getArguments_->end(); it++) | 54 it = getArguments_.begin(); it != getArguments_.end(); ++it) |
55 { | 55 { |
56 result[it->first] = it->second; | 56 result[it->first] = it->second; |
57 } | 57 } |
58 | 58 |
59 return true; | 59 return true; |
61 | 61 |
62 | 62 |
63 bool RestApi::IsGetAccepted(const UriComponents& uri) | 63 bool RestApi::IsGetAccepted(const UriComponents& uri) |
64 { | 64 { |
65 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 65 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
66 it != getHandlers_.end(); it++) | 66 it != getHandlers_.end(); ++it) |
67 { | 67 { |
68 if (it->first->Match(uri)) | 68 if (it->first->Match(uri)) |
69 { | 69 { |
70 return true; | 70 return true; |
71 } | 71 } |
75 } | 75 } |
76 | 76 |
77 bool RestApi::IsPutAccepted(const UriComponents& uri) | 77 bool RestApi::IsPutAccepted(const UriComponents& uri) |
78 { | 78 { |
79 for (PutHandlers::const_iterator it = putHandlers_.begin(); | 79 for (PutHandlers::const_iterator it = putHandlers_.begin(); |
80 it != putHandlers_.end(); it++) | 80 it != putHandlers_.end(); ++it) |
81 { | 81 { |
82 if (it->first->Match(uri)) | 82 if (it->first->Match(uri)) |
83 { | 83 { |
84 return true; | 84 return true; |
85 } | 85 } |
89 } | 89 } |
90 | 90 |
91 bool RestApi::IsPostAccepted(const UriComponents& uri) | 91 bool RestApi::IsPostAccepted(const UriComponents& uri) |
92 { | 92 { |
93 for (PostHandlers::const_iterator it = postHandlers_.begin(); | 93 for (PostHandlers::const_iterator it = postHandlers_.begin(); |
94 it != postHandlers_.end(); it++) | 94 it != postHandlers_.end(); ++it) |
95 { | 95 { |
96 if (it->first->Match(uri)) | 96 if (it->first->Match(uri)) |
97 { | 97 { |
98 return true; | 98 return true; |
99 } | 99 } |
103 } | 103 } |
104 | 104 |
105 bool RestApi::IsDeleteAccepted(const UriComponents& uri) | 105 bool RestApi::IsDeleteAccepted(const UriComponents& uri) |
106 { | 106 { |
107 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); | 107 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); |
108 it != deleteHandlers_.end(); it++) | 108 it != deleteHandlers_.end(); ++it) |
109 { | 109 { |
110 if (it->first->Match(uri)) | 110 if (it->first->Match(uri)) |
111 { | 111 { |
112 return true; | 112 return true; |
113 } | 113 } |
145 } | 145 } |
146 | 146 |
147 RestApi::~RestApi() | 147 RestApi::~RestApi() |
148 { | 148 { |
149 for (GetHandlers::iterator it = getHandlers_.begin(); | 149 for (GetHandlers::iterator it = getHandlers_.begin(); |
150 it != getHandlers_.end(); it++) | 150 it != getHandlers_.end(); ++it) |
151 { | 151 { |
152 delete it->first; | 152 delete it->first; |
153 } | 153 } |
154 | 154 |
155 for (PutHandlers::iterator it = putHandlers_.begin(); | 155 for (PutHandlers::iterator it = putHandlers_.begin(); |
156 it != putHandlers_.end(); it++) | 156 it != putHandlers_.end(); ++it) |
157 { | 157 { |
158 delete it->first; | 158 delete it->first; |
159 } | 159 } |
160 | 160 |
161 for (PostHandlers::iterator it = postHandlers_.begin(); | 161 for (PostHandlers::iterator it = postHandlers_.begin(); |
162 it != postHandlers_.end(); it++) | 162 it != postHandlers_.end(); ++it) |
163 { | 163 { |
164 delete it->first; | 164 delete it->first; |
165 } | 165 } |
166 | 166 |
167 for (DeleteHandlers::iterator it = deleteHandlers_.begin(); | 167 for (DeleteHandlers::iterator it = deleteHandlers_.begin(); |
168 it != deleteHandlers_.end(); it++) | 168 it != deleteHandlers_.end(); ++it) |
169 { | 169 { |
170 delete it->first; | 170 delete it->first; |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
192 UriComponents trailing; | 192 UriComponents trailing; |
193 | 193 |
194 if (method == HttpMethod_Get) | 194 if (method == HttpMethod_Get) |
195 { | 195 { |
196 for (GetHandlers::const_iterator it = getHandlers_.begin(); | 196 for (GetHandlers::const_iterator it = getHandlers_.begin(); |
197 it != getHandlers_.end(); it++) | 197 it != getHandlers_.end(); ++it) |
198 { | 198 { |
199 if (it->first->Match(components, trailing, uri)) | 199 if (it->first->Match(components, trailing, uri)) |
200 { | 200 { |
201 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); | 201 //LOG(INFO) << "REST GET call on: " << Toolbox::FlattenUri(uri); |
202 ok = true; | 202 ok = true; |
203 GetCall call; | 203 GetCall call(restOutput, *this, headers, components, trailing, uri, getArguments); |
204 call.output_ = &restOutput; | |
205 call.context_ = this; | |
206 call.httpHeaders_ = &headers; | |
207 call.uriComponents_ = &components; | |
208 call.trailing_ = &trailing; | |
209 call.fullUri_ = &uri; | |
210 | |
211 call.getArguments_ = &getArguments; | |
212 it->second(call); | 204 it->second(call); |
213 } | 205 } |
214 } | 206 } |
215 } | 207 } |
216 else if (method == HttpMethod_Put) | 208 else if (method == HttpMethod_Put) |
217 { | 209 { |
218 for (PutHandlers::const_iterator it = putHandlers_.begin(); | 210 for (PutHandlers::const_iterator it = putHandlers_.begin(); |
219 it != putHandlers_.end(); it++) | 211 it != putHandlers_.end(); ++it) |
220 { | 212 { |
221 if (it->first->Match(components, trailing, uri)) | 213 if (it->first->Match(components, trailing, uri)) |
222 { | 214 { |
223 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); | 215 //LOG(INFO) << "REST PUT call on: " << Toolbox::FlattenUri(uri); |
224 ok = true; | 216 ok = true; |
225 PutCall call; | 217 PutCall call(restOutput, *this, headers, components, trailing, uri, postData); |
226 call.output_ = &restOutput; | |
227 call.context_ = this; | |
228 call.httpHeaders_ = &headers; | |
229 call.uriComponents_ = &components; | |
230 call.trailing_ = &trailing; | |
231 call.fullUri_ = &uri; | |
232 | |
233 call.data_ = &postData; | |
234 it->second(call); | 218 it->second(call); |
235 } | 219 } |
236 } | 220 } |
237 } | 221 } |
238 else if (method == HttpMethod_Post) | 222 else if (method == HttpMethod_Post) |
239 { | 223 { |
240 for (PostHandlers::const_iterator it = postHandlers_.begin(); | 224 for (PostHandlers::const_iterator it = postHandlers_.begin(); |
241 it != postHandlers_.end(); it++) | 225 it != postHandlers_.end(); ++it) |
242 { | 226 { |
243 if (it->first->Match(components, trailing, uri)) | 227 if (it->first->Match(components, trailing, uri)) |
244 { | 228 { |
245 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); | 229 //LOG(INFO) << "REST POST call on: " << Toolbox::FlattenUri(uri); |
246 ok = true; | 230 ok = true; |
247 PostCall call; | 231 PostCall call(restOutput, *this, headers, components, trailing, uri, postData); |
248 call.output_ = &restOutput; | |
249 call.context_ = this; | |
250 call.httpHeaders_ = &headers; | |
251 call.uriComponents_ = &components; | |
252 call.trailing_ = &trailing; | |
253 call.fullUri_ = &uri; | |
254 | |
255 call.data_ = &postData; | |
256 it->second(call); | 232 it->second(call); |
257 } | 233 } |
258 } | 234 } |
259 } | 235 } |
260 else if (method == HttpMethod_Delete) | 236 else if (method == HttpMethod_Delete) |
261 { | 237 { |
262 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); | 238 for (DeleteHandlers::const_iterator it = deleteHandlers_.begin(); |
263 it != deleteHandlers_.end(); it++) | 239 it != deleteHandlers_.end(); ++it) |
264 { | 240 { |
265 if (it->first->Match(components, trailing, uri)) | 241 if (it->first->Match(components, trailing, uri)) |
266 { | 242 { |
267 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); | 243 //LOG(INFO) << "REST DELETE call on: " << Toolbox::FlattenUri(uri); |
268 ok = true; | 244 ok = true; |
269 DeleteCall call; | 245 DeleteCall call(restOutput, *this, headers, components, trailing, uri); |
270 call.output_ = &restOutput; | |
271 call.context_ = this; | |
272 call.httpHeaders_ = &headers; | |
273 call.uriComponents_ = &components; | |
274 call.trailing_ = &trailing; | |
275 call.fullUri_ = &uri; | |
276 it->second(call); | 246 it->second(call); |
277 } | 247 } |
278 } | 248 } |
279 } | 249 } |
280 | 250 |