Mercurial > hg > orthanc
annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3702:643b5ee86f92
fix handling of errors of OrthancPluginStorageRemove()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Feb 2020 14:36:42 +0100 |
parents | 445bda258245 |
children | e64432336055 edabdf07ee83 |
rev | line source |
---|---|
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3478
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
2850 | 23 * |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "OrthancPluginCppWrapper.h" |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
36 #include <boost/thread.hpp> |
3394 | 37 #include <boost/algorithm/string/predicate.hpp> |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 #include <json/reader.h> |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
39 #include <json/writer.h> |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 namespace OrthancPlugins |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
3028 | 44 static OrthancPluginContext* globalContext_ = NULL; |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
45 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
46 |
3028 | 47 void SetGlobalContext(OrthancPluginContext* context) |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
48 { |
3028 | 49 if (context == NULL) |
50 { | |
51 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
52 } | |
53 else if (globalContext_ == NULL) | |
54 { | |
55 globalContext_ = context; | |
56 } | |
57 else | |
58 { | |
59 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
60 } | |
3026 | 61 } |
62 | |
63 | |
3028 | 64 bool HasGlobalContext() |
65 { | |
66 return globalContext_ != NULL; | |
67 } | |
68 | |
69 | |
70 OrthancPluginContext* GetGlobalContext() | |
71 { | |
72 if (globalContext_ == NULL) | |
73 { | |
74 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
75 } | |
76 else | |
77 { | |
78 return globalContext_; | |
79 } | |
80 } | |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
81 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
82 |
3028 | 83 void MemoryBuffer::Check(OrthancPluginErrorCode code) |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
84 { |
3028 | 85 if (code != OrthancPluginErrorCode_Success) |
86 { | |
87 // Prevent using garbage information | |
88 buffer_.data = NULL; | |
89 buffer_.size = 0; | |
90 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
91 } | |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
92 } |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
93 |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
94 |
3028 | 95 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code) |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
96 { |
3028 | 97 if (code != OrthancPluginErrorCode_Success) |
98 { | |
99 // Prevent using garbage information | |
100 buffer_.data = NULL; | |
101 buffer_.size = 0; | |
102 } | |
103 | |
104 if (code == OrthancPluginErrorCode_Success) | |
105 { | |
106 return true; | |
107 } | |
108 else if (code == OrthancPluginErrorCode_UnknownResource || | |
109 code == OrthancPluginErrorCode_InexistentItem) | |
110 { | |
111 return false; | |
112 } | |
113 else | |
114 { | |
115 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
116 } | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
117 } |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
118 |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
119 |
3028 | 120 MemoryBuffer::MemoryBuffer() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 buffer_.data = NULL; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 buffer_.size = 0; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
3028 | 126 |
127 void MemoryBuffer::Clear() | |
3026 | 128 { |
3028 | 129 if (buffer_.data != NULL) |
130 { | |
131 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); | |
132 buffer_.data = NULL; | |
133 buffer_.size = 0; | |
134 } | |
3026 | 135 } |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
3026 | 137 |
3028 | 138 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) |
139 { | |
140 Clear(); | |
141 | |
142 buffer_.data = other.data; | |
143 buffer_.size = other.size; | |
144 | |
145 other.data = NULL; | |
146 other.size = 0; | |
147 } | |
3026 | 148 |
149 | |
3320 | 150 void MemoryBuffer::Swap(MemoryBuffer& other) |
151 { | |
152 std::swap(buffer_.data, other.buffer_.data); | |
153 std::swap(buffer_.size, other.buffer_.size); | |
154 } | |
155 | |
156 | |
3028 | 157 OrthancPluginMemoryBuffer MemoryBuffer::Release() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 { |
3028 | 159 OrthancPluginMemoryBuffer result = buffer_; |
160 | |
3026 | 161 buffer_.data = NULL; |
162 buffer_.size = 0; | |
3028 | 163 |
164 return result; | |
3026 | 165 } |
3028 | 166 |
167 | |
168 void MemoryBuffer::ToString(std::string& target) const | |
169 { | |
170 if (buffer_.size == 0) | |
171 { | |
172 target.clear(); | |
173 } | |
174 else | |
175 { | |
176 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size); | |
177 } | |
178 } | |
3026 | 179 |
180 | |
3028 | 181 void MemoryBuffer::ToJson(Json::Value& target) const |
182 { | |
183 if (buffer_.data == NULL || | |
184 buffer_.size == 0) | |
185 { | |
186 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
187 } | |
3026 | 188 |
3028 | 189 const char* tmp = reinterpret_cast<const char*>(buffer_.data); |
3026 | 190 |
3028 | 191 Json::Reader reader; |
192 if (!reader.parse(tmp, tmp + buffer_.size, target)) | |
193 { | |
194 LogError("Cannot convert some memory buffer to JSON"); | |
195 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
196 } | |
197 } | |
3026 | 198 |
199 | |
3028 | 200 bool MemoryBuffer::RestApiGet(const std::string& uri, |
201 bool applyPlugins) | |
3026 | 202 { |
3028 | 203 Clear(); |
3026 | 204 |
3028 | 205 if (applyPlugins) |
206 { | |
207 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); | |
208 } | |
209 else | |
210 { | |
211 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); | |
212 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 |
3028 | 215 bool MemoryBuffer::RestApiGet(const std::string& uri, |
216 const std::map<std::string, std::string>& httpHeaders, | |
217 bool applyPlugins) | |
3026 | 218 { |
3028 | 219 Clear(); |
220 | |
221 std::vector<const char*> headersKeys; | |
222 std::vector<const char*> headersValues; | |
3039 | 223 |
224 for (std::map<std::string, std::string>::const_iterator | |
225 it = httpHeaders.begin(); it != httpHeaders.end(); it++) | |
3028 | 226 { |
227 headersKeys.push_back(it->first.c_str()); | |
228 headersValues.push_back(it->second.c_str()); | |
229 } | |
230 | |
3039 | 231 return CheckHttp(OrthancPluginRestApiGet2( |
232 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(), | |
233 (headersKeys.empty() ? NULL : &headersKeys[0]), | |
234 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins)); | |
3026 | 235 } |
3028 | 236 |
237 bool MemoryBuffer::RestApiPost(const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
238 const void* body, |
3028 | 239 size_t bodySize, |
240 bool applyPlugins) | |
241 { | |
242 Clear(); | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
243 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
244 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
245 const char* b = reinterpret_cast<const char*>(body); |
3028 | 246 |
247 if (applyPlugins) | |
248 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
249 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 250 } |
251 else | |
252 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
253 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 254 } |
255 } | |
3026 | 256 |
257 | |
3028 | 258 bool MemoryBuffer::RestApiPut(const std::string& uri, |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
259 const void* body, |
3028 | 260 size_t bodySize, |
261 bool applyPlugins) | |
262 { | |
263 Clear(); | |
3026 | 264 |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
265 // Cast for compatibility with Orthanc SDK <= 1.5.6 |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
266 const char* b = reinterpret_cast<const char*>(body); |
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
267 |
3028 | 268 if (applyPlugins) |
269 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
270 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 271 } |
272 else | |
273 { | |
3405
408ffcb4038f
reorganizing build instructions
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3404
diff
changeset
|
274 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); |
3028 | 275 } |
3026 | 276 } |
3028 | 277 |
3026 | 278 |
3028 | 279 bool MemoryBuffer::RestApiPost(const std::string& uri, |
280 const Json::Value& body, | |
281 bool applyPlugins) | |
3026 | 282 { |
3028 | 283 Json::FastWriter writer; |
284 return RestApiPost(uri, writer.write(body), applyPlugins); | |
3026 | 285 } |
286 | |
3028 | 287 |
288 bool MemoryBuffer::RestApiPut(const std::string& uri, | |
289 const Json::Value& body, | |
290 bool applyPlugins) | |
291 { | |
292 Json::FastWriter writer; | |
293 return RestApiPut(uri, writer.write(body), applyPlugins); | |
294 } | |
3026 | 295 |
3028 | 296 |
297 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
298 OrthancPluginCreateDicomFlags flags) | |
299 { | |
300 Clear(); | |
301 | |
302 Json::FastWriter writer; | |
303 std::string s = writer.write(tags); | |
3026 | 304 |
3028 | 305 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); |
3026 | 306 } |
3028 | 307 |
308 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
309 const OrthancImage& pixelData, | |
310 OrthancPluginCreateDicomFlags flags) | |
3026 | 311 { |
3028 | 312 Clear(); |
313 | |
314 Json::FastWriter writer; | |
315 std::string s = writer.write(tags); | |
316 | |
317 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); | |
3026 | 318 } |
3028 | 319 |
320 | |
321 void MemoryBuffer::ReadFile(const std::string& path) | |
322 { | |
323 Clear(); | |
324 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); | |
325 } | |
3026 | 326 |
327 | |
3028 | 328 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) |
3026 | 329 { |
3028 | 330 Clear(); |
331 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); | |
3026 | 332 } |
333 | |
334 | |
3028 | 335 void OrthancString::Assign(char* str) |
336 { | |
3440 | 337 Clear(); |
338 | |
339 if (str != NULL) | |
3028 | 340 { |
341 str_ = str; | |
342 } | |
343 } | |
3026 | 344 |
345 | |
3028 | 346 void OrthancString::Clear() |
347 { | |
348 if (str_ != NULL) | |
349 { | |
350 OrthancPluginFreeString(GetGlobalContext(), str_); | |
351 str_ = NULL; | |
352 } | |
353 } | |
3026 | 354 |
355 | |
3028 | 356 void OrthancString::ToString(std::string& target) const |
357 { | |
358 if (str_ == NULL) | |
359 { | |
360 target.clear(); | |
361 } | |
362 else | |
363 { | |
364 target.assign(str_); | |
365 } | |
366 } | |
3026 | 367 |
368 | |
3028 | 369 void OrthancString::ToJson(Json::Value& target) const |
370 { | |
371 if (str_ == NULL) | |
372 { | |
373 LogError("Cannot convert an empty memory buffer to JSON"); | |
374 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
375 } | |
376 | |
377 Json::Reader reader; | |
378 if (!reader.parse(str_, target)) | |
379 { | |
380 LogError("Cannot convert some memory buffer to JSON"); | |
381 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
382 } | |
383 } | |
3026 | 384 |
385 | |
3028 | 386 void MemoryBuffer::DicomToJson(Json::Value& target, |
387 OrthancPluginDicomToJsonFormat format, | |
388 OrthancPluginDicomToJsonFlags flags, | |
389 uint32_t maxStringLength) | |
390 { | |
391 OrthancString str; | |
392 str.Assign(OrthancPluginDicomBufferToJson | |
393 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); | |
394 str.ToJson(target); | |
395 } | |
3026 | 396 |
397 | |
3028 | 398 bool MemoryBuffer::HttpGet(const std::string& url, |
399 const std::string& username, | |
400 const std::string& password) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 Clear(); |
3028 | 403 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), |
404 username.empty() ? NULL : username.c_str(), | |
405 password.empty() ? NULL : password.c_str())); | |
3026 | 406 } |
407 | |
408 | |
3028 | 409 bool MemoryBuffer::HttpPost(const std::string& url, |
410 const std::string& body, | |
411 const std::string& username, | |
412 const std::string& password) | |
3026 | 413 { |
3028 | 414 Clear(); |
415 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), | |
416 body.c_str(), body.size(), | |
417 username.empty() ? NULL : username.c_str(), | |
418 password.empty() ? NULL : password.c_str())); | |
3026 | 419 } |
420 | |
421 | |
3028 | 422 bool MemoryBuffer::HttpPut(const std::string& url, |
423 const std::string& body, | |
424 const std::string& username, | |
425 const std::string& password) | |
3026 | 426 { |
3028 | 427 Clear(); |
428 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), | |
429 body.empty() ? NULL : body.c_str(), | |
430 body.size(), | |
431 username.empty() ? NULL : username.c_str(), | |
432 password.empty() ? NULL : password.c_str())); | |
3026 | 433 } |
434 | |
3028 | 435 |
436 void MemoryBuffer::GetDicomInstance(const std::string& instanceId) | |
3026 | 437 { |
3028 | 438 Clear(); |
439 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); | |
3026 | 440 } |
441 | |
442 | |
3028 | 443 bool HttpDelete(const std::string& url, |
444 const std::string& username, | |
445 const std::string& password) | |
446 { | |
447 OrthancPluginErrorCode error = OrthancPluginHttpDelete | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
448 (GetGlobalContext(), url.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
449 username.empty() ? NULL : username.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
450 password.empty() ? NULL : password.c_str()); |
3028 | 451 |
452 if (error == OrthancPluginErrorCode_Success) | |
453 { | |
454 return true; | |
455 } | |
456 else if (error == OrthancPluginErrorCode_UnknownResource || | |
457 error == OrthancPluginErrorCode_InexistentItem) | |
458 { | |
459 return false; | |
460 } | |
461 else | |
462 { | |
463 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
464 } | |
465 } | |
3026 | 466 |
467 | |
3028 | 468 void LogError(const std::string& message) |
469 { | |
470 if (HasGlobalContext()) | |
471 { | |
472 OrthancPluginLogError(GetGlobalContext(), message.c_str()); | |
473 } | |
474 } | |
3026 | 475 |
476 | |
3028 | 477 void LogWarning(const std::string& message) |
478 { | |
479 if (HasGlobalContext()) | |
480 { | |
481 OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); | |
482 } | |
483 } | |
484 | |
485 | |
486 void LogInfo(const std::string& message) | |
487 { | |
488 if (HasGlobalContext()) | |
489 { | |
490 OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); | |
491 } | |
492 } | |
3026 | 493 |
494 | |
3421
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
495 void OrthancConfiguration::LoadConfiguration() |
3028 | 496 { |
497 OrthancString str; | |
498 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); | |
3026 | 499 |
3028 | 500 if (str.GetContent() == NULL) |
501 { | |
502 LogError("Cannot access the Orthanc configuration"); | |
503 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
504 } | |
3026 | 505 |
3028 | 506 str.ToJson(configuration_); |
507 | |
508 if (configuration_.type() != Json::objectValue) | |
509 { | |
510 LogError("Unable to read the Orthanc configuration"); | |
511 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
512 } | |
513 } | |
3421
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
514 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
515 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
516 OrthancConfiguration::OrthancConfiguration() |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
517 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
518 LoadConfiguration(); |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
519 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
520 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
521 |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
522 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration) |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
523 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
524 if (loadConfiguration) |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
525 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
526 LoadConfiguration(); |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
527 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
528 else |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
529 { |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
530 configuration_ = Json::objectValue; |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
531 } |
decbede6e3ad
OrthancPlugins::OrthancConfiguration(bool)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3420
diff
changeset
|
532 } |
3026 | 533 |
534 | |
3028 | 535 std::string OrthancConfiguration::GetPath(const std::string& key) const |
3026 | 536 { |
3028 | 537 if (path_.empty()) |
538 { | |
539 return key; | |
540 } | |
541 else | |
542 { | |
543 return path_ + "." + key; | |
544 } | |
3026 | 545 } |
3028 | 546 |
547 | |
548 bool OrthancConfiguration::IsSection(const std::string& key) const | |
3026 | 549 { |
3028 | 550 assert(configuration_.type() == Json::objectValue); |
551 | |
552 return (configuration_.isMember(key) && | |
553 configuration_[key].type() == Json::objectValue); | |
3026 | 554 } |
555 | |
556 | |
3028 | 557 void OrthancConfiguration::GetSection(OrthancConfiguration& target, |
558 const std::string& key) const | |
3026 | 559 { |
3028 | 560 assert(configuration_.type() == Json::objectValue); |
3026 | 561 |
3028 | 562 target.path_ = GetPath(key); |
3026 | 563 |
3028 | 564 if (!configuration_.isMember(key)) |
565 { | |
566 target.configuration_ = Json::objectValue; | |
567 } | |
568 else | |
569 { | |
570 if (configuration_[key].type() != Json::objectValue) | |
571 { | |
572 LogError("The configuration section \"" + target.path_ + | |
573 "\" is not an associative array as expected"); | |
574 | |
575 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
576 } | |
577 | |
578 target.configuration_ = configuration_[key]; | |
579 } | |
3026 | 580 } |
581 | |
582 | |
3028 | 583 bool OrthancConfiguration::LookupStringValue(std::string& target, |
584 const std::string& key) const | |
585 { | |
586 assert(configuration_.type() == Json::objectValue); | |
587 | |
588 if (!configuration_.isMember(key)) | |
589 { | |
590 return false; | |
591 } | |
3026 | 592 |
3028 | 593 if (configuration_[key].type() != Json::stringValue) |
594 { | |
595 LogError("The configuration option \"" + GetPath(key) + | |
596 "\" is not a string as expected"); | |
597 | |
598 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
599 } | |
600 | |
601 target = configuration_[key].asString(); | |
602 return true; | |
3026 | 603 } |
604 | |
605 | |
3028 | 606 bool OrthancConfiguration::LookupIntegerValue(int& target, |
607 const std::string& key) const | |
3026 | 608 { |
3028 | 609 assert(configuration_.type() == Json::objectValue); |
610 | |
611 if (!configuration_.isMember(key)) | |
612 { | |
613 return false; | |
614 } | |
615 | |
616 switch (configuration_[key].type()) | |
617 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
618 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
619 target = configuration_[key].asInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
620 return true; |
3028 | 621 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
622 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
623 target = configuration_[key].asUInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
624 return true; |
3028 | 625 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
626 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
627 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
628 "\" is not an integer as expected"); |
3028 | 629 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
630 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 631 } |
3026 | 632 } |
633 | |
634 | |
3028 | 635 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, |
636 const std::string& key) const | |
637 { | |
638 int tmp; | |
639 if (!LookupIntegerValue(tmp, key)) | |
640 { | |
641 return false; | |
642 } | |
3026 | 643 |
3028 | 644 if (tmp < 0) |
645 { | |
646 LogError("The configuration option \"" + GetPath(key) + | |
647 "\" is not a positive integer as expected"); | |
648 | |
649 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
650 } | |
651 else | |
652 { | |
653 target = static_cast<unsigned int>(tmp); | |
654 return true; | |
655 } | |
656 } | |
3026 | 657 |
658 | |
3028 | 659 bool OrthancConfiguration::LookupBooleanValue(bool& target, |
660 const std::string& key) const | |
3026 | 661 { |
3028 | 662 assert(configuration_.type() == Json::objectValue); |
663 | |
664 if (!configuration_.isMember(key)) | |
3026 | 665 { |
3028 | 666 return false; |
667 } | |
668 | |
669 if (configuration_[key].type() != Json::booleanValue) | |
670 { | |
671 LogError("The configuration option \"" + GetPath(key) + | |
672 "\" is not a Boolean as expected"); | |
3026 | 673 |
674 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
675 } | |
676 | |
3028 | 677 target = configuration_[key].asBool(); |
678 return true; | |
3026 | 679 } |
3028 | 680 |
681 | |
682 bool OrthancConfiguration::LookupFloatValue(float& target, | |
683 const std::string& key) const | |
684 { | |
685 assert(configuration_.type() == Json::objectValue); | |
686 | |
687 if (!configuration_.isMember(key)) | |
688 { | |
689 return false; | |
690 } | |
691 | |
692 switch (configuration_[key].type()) | |
693 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
694 case Json::realValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
695 target = configuration_[key].asFloat(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
696 return true; |
3028 | 697 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
698 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
699 target = static_cast<float>(configuration_[key].asInt()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
700 return true; |
3028 | 701 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
702 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
703 target = static_cast<float>(configuration_[key].asUInt()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
704 return true; |
3028 | 705 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
706 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
707 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
708 "\" is not an integer as expected"); |
3028 | 709 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
710 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 711 } |
712 } | |
3026 | 713 |
714 | |
3028 | 715 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
716 const std::string& key, | |
717 bool allowSingleString) const | |
3026 | 718 { |
3028 | 719 assert(configuration_.type() == Json::objectValue); |
720 | |
721 target.clear(); | |
722 | |
723 if (!configuration_.isMember(key)) | |
724 { | |
725 return false; | |
726 } | |
727 | |
728 switch (configuration_[key].type()) | |
729 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
730 case Json::arrayValue: |
3028 | 731 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
732 bool ok = true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
733 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
734 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
3028 | 735 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
736 if (configuration_[key][i].type() == Json::stringValue) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
737 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
738 target.push_back(configuration_[key][i].asString()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
739 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
740 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
741 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
742 ok = false; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
743 } |
3028 | 744 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
745 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
746 if (ok) |
3028 | 747 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
748 return true; |
3028 | 749 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
750 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
751 break; |
3028 | 752 } |
753 | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
754 case Json::stringValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
755 if (allowSingleString) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
756 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
757 target.push_back(configuration_[key].asString()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
758 return true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
759 } |
3028 | 760 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
761 break; |
3028 | 762 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
763 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
764 break; |
3028 | 765 } |
766 | |
3026 | 767 LogError("The configuration option \"" + GetPath(key) + |
3028 | 768 "\" is not a list of strings as expected"); |
3026 | 769 |
770 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
771 } | |
772 | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
773 |
3028 | 774 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target, |
775 const std::string& key, | |
776 bool allowSingleString) const | |
777 { | |
778 std::list<std::string> lst; | |
779 | |
780 if (LookupListOfStrings(lst, key, allowSingleString)) | |
781 { | |
782 target.clear(); | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
783 |
3028 | 784 for (std::list<std::string>::const_iterator |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
785 it = lst.begin(); it != lst.end(); ++it) |
3028 | 786 { |
787 target.insert(*it); | |
788 } | |
3026 | 789 |
3028 | 790 return true; |
791 } | |
792 else | |
793 { | |
794 return false; | |
795 } | |
3026 | 796 } |
797 | |
3028 | 798 |
799 std::string OrthancConfiguration::GetStringValue(const std::string& key, | |
800 const std::string& defaultValue) const | |
3026 | 801 { |
3028 | 802 std::string tmp; |
803 if (LookupStringValue(tmp, key)) | |
804 { | |
805 return tmp; | |
806 } | |
807 else | |
808 { | |
809 return defaultValue; | |
810 } | |
3026 | 811 } |
812 | |
813 | |
3028 | 814 int OrthancConfiguration::GetIntegerValue(const std::string& key, |
815 int defaultValue) const | |
3026 | 816 { |
3028 | 817 int tmp; |
818 if (LookupIntegerValue(tmp, key)) | |
819 { | |
820 return tmp; | |
821 } | |
822 else | |
823 { | |
824 return defaultValue; | |
825 } | |
3026 | 826 } |
827 | |
3028 | 828 |
829 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, | |
830 unsigned int defaultValue) const | |
3026 | 831 { |
3028 | 832 unsigned int tmp; |
833 if (LookupUnsignedIntegerValue(tmp, key)) | |
834 { | |
835 return tmp; | |
836 } | |
837 else | |
838 { | |
839 return defaultValue; | |
840 } | |
3026 | 841 } |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
842 |
3026 | 843 |
3028 | 844 bool OrthancConfiguration::GetBooleanValue(const std::string& key, |
845 bool defaultValue) const | |
3026 | 846 { |
3028 | 847 bool tmp; |
848 if (LookupBooleanValue(tmp, key)) | |
849 { | |
850 return tmp; | |
851 } | |
852 else | |
853 { | |
854 return defaultValue; | |
855 } | |
3026 | 856 } |
857 | |
3028 | 858 |
859 float OrthancConfiguration::GetFloatValue(const std::string& key, | |
860 float defaultValue) const | |
3026 | 861 { |
3028 | 862 float tmp; |
863 if (LookupFloatValue(tmp, key)) | |
864 { | |
865 return tmp; | |
866 } | |
867 else | |
868 { | |
869 return defaultValue; | |
870 } | |
3026 | 871 } |
872 | |
873 | |
3028 | 874 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target, |
875 const std::string& key) const | |
3026 | 876 { |
3028 | 877 assert(configuration_.type() == Json::objectValue); |
878 | |
879 target.clear(); | |
880 | |
881 if (!configuration_.isMember(key)) | |
882 { | |
883 return; | |
884 } | |
3026 | 885 |
3028 | 886 if (configuration_[key].type() != Json::objectValue) |
887 { | |
888 LogError("The configuration option \"" + GetPath(key) + | |
889 "\" is not a string as expected"); | |
890 | |
891 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
892 } | |
3026 | 893 |
3028 | 894 Json::Value::Members members = configuration_[key].getMemberNames(); |
895 | |
896 for (size_t i = 0; i < members.size(); i++) | |
3026 | 897 { |
3028 | 898 const Json::Value& value = configuration_[key][members[i]]; |
899 | |
900 if (value.type() == Json::stringValue) | |
3026 | 901 { |
3028 | 902 target[members[i]] = value.asString(); |
3026 | 903 } |
904 else | |
905 { | |
3028 | 906 LogError("The configuration option \"" + GetPath(key) + |
907 "\" is not a dictionary mapping strings to strings"); | |
908 | |
909 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
3026 | 910 } |
911 } | |
3028 | 912 } |
3026 | 913 |
3028 | 914 |
915 void OrthancImage::Clear() | |
916 { | |
917 if (image_ != NULL) | |
918 { | |
919 OrthancPluginFreeImage(GetGlobalContext(), image_); | |
920 image_ = NULL; | |
921 } | |
922 } | |
923 | |
924 | |
3236 | 925 void OrthancImage::CheckImageAvailable() const |
3028 | 926 { |
927 if (image_ == NULL) | |
928 { | |
929 LogError("Trying to access a NULL image"); | |
930 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
931 } | |
932 } | |
933 | |
934 | |
935 OrthancImage::OrthancImage() : | |
936 image_(NULL) | |
937 { | |
938 } | |
939 | |
940 | |
941 OrthancImage::OrthancImage(OrthancPluginImage* image) : | |
942 image_(image) | |
943 { | |
944 } | |
945 | |
946 | |
947 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
948 uint32_t width, | |
949 uint32_t height) | |
950 { | |
951 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); | |
952 | |
953 if (image_ == NULL) | |
954 { | |
955 LogError("Cannot create an image"); | |
956 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
957 } | |
958 } | |
959 | |
960 | |
961 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
962 uint32_t width, | |
963 uint32_t height, | |
964 uint32_t pitch, | |
965 void* buffer) | |
966 { | |
967 image_ = OrthancPluginCreateImageAccessor | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
968 (GetGlobalContext(), format, width, height, pitch, buffer); |
3028 | 969 |
970 if (image_ == NULL) | |
971 { | |
972 LogError("Cannot create an image accessor"); | |
973 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
974 } | |
975 } | |
976 | |
977 void OrthancImage::UncompressPngImage(const void* data, | |
978 size_t size) | |
979 { | |
980 Clear(); | |
981 | |
982 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); | |
983 | |
984 if (image_ == NULL) | |
985 { | |
986 LogError("Cannot uncompress a PNG image"); | |
987 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
988 } | |
989 } | |
990 | |
991 | |
992 void OrthancImage::UncompressJpegImage(const void* data, | |
993 size_t size) | |
994 { | |
995 Clear(); | |
996 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); | |
997 if (image_ == NULL) | |
998 { | |
999 LogError("Cannot uncompress a JPEG image"); | |
1000 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1001 } | |
1002 } | |
1003 | |
1004 | |
1005 void OrthancImage::DecodeDicomImage(const void* data, | |
1006 size_t size, | |
1007 unsigned int frame) | |
1008 { | |
1009 Clear(); | |
1010 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); | |
1011 if (image_ == NULL) | |
1012 { | |
1013 LogError("Cannot uncompress a DICOM image"); | |
1014 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1015 } | |
1016 } | |
1017 | |
1018 | |
3236 | 1019 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const |
3028 | 1020 { |
1021 CheckImageAvailable(); | |
1022 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); | |
1023 } | |
1024 | |
1025 | |
3236 | 1026 unsigned int OrthancImage::GetWidth() const |
3028 | 1027 { |
1028 CheckImageAvailable(); | |
1029 return OrthancPluginGetImageWidth(GetGlobalContext(), image_); | |
1030 } | |
1031 | |
1032 | |
3236 | 1033 unsigned int OrthancImage::GetHeight() const |
3028 | 1034 { |
1035 CheckImageAvailable(); | |
1036 return OrthancPluginGetImageHeight(GetGlobalContext(), image_); | |
1037 } | |
1038 | |
1039 | |
3236 | 1040 unsigned int OrthancImage::GetPitch() const |
3028 | 1041 { |
1042 CheckImageAvailable(); | |
1043 return OrthancPluginGetImagePitch(GetGlobalContext(), image_); | |
1044 } | |
1045 | |
1046 | |
3236 | 1047 const void* OrthancImage::GetBuffer() const |
3028 | 1048 { |
1049 CheckImageAvailable(); | |
1050 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); | |
1051 } | |
1052 | |
1053 | |
3236 | 1054 void OrthancImage::CompressPngImage(MemoryBuffer& target) const |
3028 | 1055 { |
1056 CheckImageAvailable(); | |
1057 | |
3320 | 1058 OrthancPlugins::MemoryBuffer answer; |
1059 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1060 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
1061 | |
3320 | 1062 target.Swap(answer); |
3028 | 1063 } |
1064 | |
1065 | |
1066 void OrthancImage::CompressJpegImage(MemoryBuffer& target, | |
3236 | 1067 uint8_t quality) const |
3028 | 1068 { |
1069 CheckImageAvailable(); | |
1070 | |
3320 | 1071 OrthancPlugins::MemoryBuffer answer; |
1072 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1073 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
1074 | |
3320 | 1075 target.Swap(answer); |
3028 | 1076 } |
1077 | |
1078 | |
3236 | 1079 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const |
3028 | 1080 { |
1081 CheckImageAvailable(); | |
1082 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), | |
1083 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | |
1084 } | |
1085 | |
1086 | |
1087 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, | |
3236 | 1088 uint8_t quality) const |
3028 | 1089 { |
1090 CheckImageAvailable(); | |
1091 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), | |
1092 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | |
1093 } | |
1094 | |
1095 | |
1096 | |
1097 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 | |
1098 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : | |
1099 matcher_(NULL), | |
1100 worklist_(worklist) | |
1101 { | |
1102 if (worklist_ == NULL) | |
1103 { | |
1104 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1105 } | |
1106 } | |
1107 | |
1108 | |
1109 void FindMatcher::SetupDicom(const void* query, | |
1110 uint32_t size) | |
1111 { | |
1112 worklist_ = NULL; | |
1113 | |
1114 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); | |
1115 if (matcher_ == NULL) | |
1116 { | |
1117 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1118 } | |
1119 } | |
1120 | |
1121 | |
1122 FindMatcher::~FindMatcher() | |
1123 { | |
1124 // The "worklist_" field | |
1125 | |
1126 if (matcher_ != NULL) | |
1127 { | |
1128 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); | |
1129 } | |
1130 } | |
1131 | |
1132 | |
1133 | |
1134 bool FindMatcher::IsMatch(const void* dicom, | |
1135 uint32_t size) const | |
1136 { | |
1137 int32_t result; | |
1138 | |
1139 if (matcher_ != NULL) | |
1140 { | |
1141 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); | |
1142 } | |
1143 else if (worklist_ != NULL) | |
1144 { | |
1145 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); | |
1146 } | |
1147 else | |
1148 { | |
1149 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1150 } | |
1151 | |
1152 if (result == 0) | |
1153 { | |
1154 return false; | |
1155 } | |
1156 else if (result == 1) | |
1157 { | |
1158 return true; | |
1159 } | |
1160 else | |
1161 { | |
1162 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1163 } | |
1164 } | |
1165 | |
1166 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | |
1167 | |
1168 void AnswerJson(const Json::Value& value, | |
1169 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1170 ) |
3028 | 1171 { |
1172 Json::StyledWriter writer; | |
1173 std::string bodyString = writer.write(value); | |
1174 | |
1175 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); | |
1176 } | |
1177 | |
1178 void AnswerString(const std::string& answer, | |
1179 const char* mimeType, | |
1180 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1181 ) |
3028 | 1182 { |
1183 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); | |
1184 } | |
1185 | |
1186 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) | |
1187 { | |
1188 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); | |
1189 } | |
1190 | |
1191 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) | |
1192 { | |
1193 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); | |
1194 } | |
1195 | |
1196 bool RestApiGetString(std::string& result, | |
1197 const std::string& uri, | |
1198 bool applyPlugins) | |
1199 { | |
1200 MemoryBuffer answer; | |
1201 if (!answer.RestApiGet(uri, applyPlugins)) | |
1202 { | |
1203 return false; | |
1204 } | |
1205 else | |
1206 { | |
1207 answer.ToString(result); | |
1208 return true; | |
1209 } | |
1210 } | |
1211 | |
1212 bool RestApiGetString(std::string& result, | |
1213 const std::string& uri, | |
1214 const std::map<std::string, std::string>& httpHeaders, | |
1215 bool applyPlugins) | |
1216 { | |
1217 MemoryBuffer answer; | |
1218 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) | |
1219 { | |
1220 return false; | |
1221 } | |
1222 else | |
1223 { | |
1224 answer.ToString(result); | |
1225 return true; | |
1226 } | |
1227 } | |
1228 | |
1229 | |
1230 | |
1231 bool RestApiGet(Json::Value& result, | |
1232 const std::string& uri, | |
1233 bool applyPlugins) | |
1234 { | |
1235 MemoryBuffer answer; | |
1236 | |
1237 if (!answer.RestApiGet(uri, applyPlugins)) | |
1238 { | |
1239 return false; | |
1240 } | |
1241 else | |
1242 { | |
1243 if (!answer.IsEmpty()) | |
1244 { | |
1245 answer.ToJson(result); | |
1246 } | |
1247 return true; | |
1248 } | |
1249 } | |
1250 | |
1251 | |
3478
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1252 bool RestApiPost(std::string& result, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1253 const std::string& uri, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1254 const void* body, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1255 size_t bodySize, |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1256 bool applyPlugins) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1257 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1258 MemoryBuffer answer; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1259 |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1260 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1261 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1262 return false; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1263 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1264 else |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1265 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1266 if (!answer.IsEmpty()) |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1267 { |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1268 result.assign(answer.GetData(), answer.GetSize()); |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1269 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1270 return true; |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1271 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1272 } |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1273 |
f93a9c6c00c5
added RestApiPost overload to retrieve a string response
Alain Mazy <alain@mazy.be>
parents:
3443
diff
changeset
|
1274 |
3028 | 1275 bool RestApiPost(Json::Value& result, |
1276 const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
1277 const void* body, |
3028 | 1278 size_t bodySize, |
1279 bool applyPlugins) | |
1280 { | |
1281 MemoryBuffer answer; | |
1282 | |
1283 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) | |
1284 { | |
1285 return false; | |
1286 } | |
1287 else | |
1288 { | |
1289 if (!answer.IsEmpty()) | |
1290 { | |
1291 answer.ToJson(result); | |
1292 } | |
1293 return true; | |
1294 } | |
1295 } | |
1296 | |
1297 | |
1298 bool RestApiPost(Json::Value& result, | |
1299 const std::string& uri, | |
1300 const Json::Value& body, | |
1301 bool applyPlugins) | |
1302 { | |
1303 Json::FastWriter writer; | |
1304 return RestApiPost(result, uri, writer.write(body), applyPlugins); | |
1305 } | |
1306 | |
1307 | |
1308 bool RestApiPut(Json::Value& result, | |
1309 const std::string& uri, | |
3400
0faae6f6e3c5
fixed some inconsistencies with pointer types in the plugin sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3399
diff
changeset
|
1310 const void* body, |
3028 | 1311 size_t bodySize, |
1312 bool applyPlugins) | |
1313 { | |
1314 MemoryBuffer answer; | |
1315 | |
1316 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) | |
1317 { | |
1318 return false; | |
1319 } | |
1320 else | |
1321 { | |
3422
8b4169a88039
ORTHANC_PLUGINS_API using visibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3421
diff
changeset
|
1322 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response |
3028 | 1323 { |
1324 answer.ToJson(result); | |
1325 } | |
1326 return true; | |
1327 } | |
1328 } | |
1329 | |
1330 | |
1331 bool RestApiPut(Json::Value& result, | |
1332 const std::string& uri, | |
1333 const Json::Value& body, | |
1334 bool applyPlugins) | |
1335 { | |
1336 Json::FastWriter writer; | |
1337 return RestApiPut(result, uri, writer.write(body), applyPlugins); | |
1338 } | |
1339 | |
1340 | |
1341 bool RestApiDelete(const std::string& uri, | |
1342 bool applyPlugins) | |
1343 { | |
1344 OrthancPluginErrorCode error; | |
1345 | |
1346 if (applyPlugins) | |
1347 { | |
1348 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); | |
1349 } | |
1350 else | |
1351 { | |
1352 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); | |
1353 } | |
1354 | |
1355 if (error == OrthancPluginErrorCode_Success) | |
1356 { | |
1357 return true; | |
1358 } | |
1359 else if (error == OrthancPluginErrorCode_UnknownResource || | |
1360 error == OrthancPluginErrorCode_InexistentItem) | |
1361 { | |
1362 return false; | |
1363 } | |
1364 else | |
1365 { | |
1366 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
1367 } | |
1368 } | |
1369 | |
1370 | |
1371 void ReportMinimalOrthancVersion(unsigned int major, | |
1372 unsigned int minor, | |
1373 unsigned int revision) | |
1374 { | |
1375 LogError("Your version of the Orthanc core (" + | |
1376 std::string(GetGlobalContext()->orthancVersion) + | |
1377 ") is too old to run this plugin (version " + | |
1378 boost::lexical_cast<std::string>(major) + "." + | |
1379 boost::lexical_cast<std::string>(minor) + "." + | |
1380 boost::lexical_cast<std::string>(revision) + | |
1381 " is required)"); | |
1382 } | |
1383 | |
1384 | |
1385 bool CheckMinimalOrthancVersion(unsigned int major, | |
1386 unsigned int minor, | |
1387 unsigned int revision) | |
1388 { | |
1389 if (!HasGlobalContext()) | |
1390 { | |
1391 LogError("Bad Orthanc context in the plugin"); | |
1392 return false; | |
1393 } | |
1394 | |
1395 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline")) | |
1396 { | |
1397 // Assume compatibility with the mainline | |
1398 return true; | |
1399 } | |
1400 | |
1401 // Parse the version of the Orthanc core | |
1402 int aa, bb, cc; | |
1403 if ( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1404 #ifdef _MSC_VER |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1405 sscanf_s |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1406 #else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1407 sscanf |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1408 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1409 (GetGlobalContext()->orthancVersion, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1410 aa < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1411 bb < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1412 cc < 0) |
3028 | 1413 { |
1414 return false; | |
1415 } | |
1416 | |
1417 unsigned int a = static_cast<unsigned int>(aa); | |
1418 unsigned int b = static_cast<unsigned int>(bb); | |
1419 unsigned int c = static_cast<unsigned int>(cc); | |
1420 | |
1421 // Check the major version number | |
1422 | |
1423 if (a > major) | |
3026 | 1424 { |
1425 return true; | |
1426 } | |
1427 | |
3028 | 1428 if (a < major) |
1429 { | |
1430 return false; | |
1431 } | |
1432 | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1433 |
3028 | 1434 // Check the minor version number |
1435 assert(a == major); | |
1436 | |
1437 if (b > minor) | |
3026 | 1438 { |
1439 return true; | |
1440 } | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1441 |
3028 | 1442 if (b < minor) |
3026 | 1443 { |
3028 | 1444 return false; |
3026 | 1445 } |
1446 | |
3028 | 1447 // Check the patch level version number |
1448 assert(a == major && b == minor); | |
3026 | 1449 |
3028 | 1450 if (c >= revision) |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1451 { |
3028 | 1452 return true; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1453 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1454 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1455 { |
3028 | 1456 return false; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1457 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1458 } |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1459 |
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1460 |
3028 | 1461 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) |
1462 const char* AutodetectMimeType(const std::string& path) | |
3026 | 1463 { |
3028 | 1464 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
1465 |
3028 | 1466 if (mime == NULL) |
1467 { | |
1468 // Should never happen, just for safety | |
1469 return "application/octet-stream"; | |
1470 } | |
1471 else | |
1472 { | |
1473 return mime; | |
1474 } | |
2848 | 1475 } |
3026 | 1476 #endif |
1477 | |
1478 | |
1479 #if HAS_ORTHANC_PLUGIN_PEERS == 1 | |
3028 | 1480 size_t OrthancPeers::GetPeerIndex(const std::string& name) const |
3026 | 1481 { |
3028 | 1482 size_t index; |
1483 if (LookupName(index, name)) | |
1484 { | |
1485 return index; | |
1486 } | |
1487 else | |
1488 { | |
1489 LogError("Inexistent peer: " + name); | |
1490 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); | |
1491 } | |
3026 | 1492 } |
2059 | 1493 |
1494 | |
3028 | 1495 OrthancPeers::OrthancPeers() : |
1496 peers_(NULL), | |
1497 timeout_(0) | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1498 { |
3028 | 1499 peers_ = OrthancPluginGetPeers(GetGlobalContext()); |
3026 | 1500 |
3028 | 1501 if (peers_ == NULL) |
3026 | 1502 { |
1503 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1504 } | |
1505 | |
3028 | 1506 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); |
1507 | |
1508 for (uint32_t i = 0; i < count; i++) | |
1509 { | |
1510 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); | |
1511 if (name == NULL) | |
1512 { | |
1513 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1514 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1515 } | |
1516 | |
1517 index_[name] = i; | |
1518 } | |
1519 } | |
1520 | |
1521 | |
1522 OrthancPeers::~OrthancPeers() | |
1523 { | |
1524 if (peers_ != NULL) | |
1525 { | |
1526 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1527 } | |
1528 } | |
1529 | |
1530 | |
1531 bool OrthancPeers::LookupName(size_t& target, | |
1532 const std::string& name) const | |
1533 { | |
1534 Index::const_iterator found = index_.find(name); | |
1535 | |
1536 if (found == index_.end()) | |
1537 { | |
1538 return false; | |
1539 } | |
1540 else | |
1541 { | |
1542 target = found->second; | |
1543 return true; | |
1544 } | |
3026 | 1545 } |
3028 | 1546 |
1547 | |
1548 std::string OrthancPeers::GetPeerName(size_t index) const | |
1549 { | |
1550 if (index >= index_.size()) | |
1551 { | |
1552 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1553 } | |
1554 else | |
1555 { | |
1556 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1557 if (s == NULL) | |
1558 { | |
1559 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1560 } | |
1561 else | |
1562 { | |
1563 return s; | |
1564 } | |
1565 } | |
1566 } | |
1567 | |
1568 | |
1569 std::string OrthancPeers::GetPeerUrl(size_t index) const | |
1570 { | |
1571 if (index >= index_.size()) | |
1572 { | |
1573 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1574 } | |
1575 else | |
1576 { | |
1577 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1578 if (s == NULL) | |
1579 { | |
1580 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1581 } | |
1582 else | |
1583 { | |
1584 return s; | |
1585 } | |
1586 } | |
1587 } | |
1588 | |
1589 | |
1590 std::string OrthancPeers::GetPeerUrl(const std::string& name) const | |
1591 { | |
1592 return GetPeerUrl(GetPeerIndex(name)); | |
1593 } | |
1594 | |
1595 | |
1596 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1597 size_t index, | |
1598 const std::string& key) const | |
1599 { | |
1600 if (index >= index_.size()) | |
1601 { | |
1602 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1603 } | |
1604 else | |
1605 { | |
1606 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str()); | |
1607 if (s == NULL) | |
1608 { | |
1609 return false; | |
1610 } | |
1611 else | |
1612 { | |
1613 value.assign(s); | |
1614 return true; | |
1615 } | |
1616 } | |
1617 } | |
1618 | |
1619 | |
1620 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1621 const std::string& peer, | |
1622 const std::string& key) const | |
1623 { | |
1624 return LookupUserProperty(value, GetPeerIndex(peer), key); | |
1625 } | |
3026 | 1626 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1627 |
3028 | 1628 bool OrthancPeers::DoGet(MemoryBuffer& target, |
1629 size_t index, | |
1630 const std::string& uri) const | |
1631 { | |
1632 if (index >= index_.size()) | |
1633 { | |
1634 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1635 } | |
1636 | |
3320 | 1637 OrthancPlugins::MemoryBuffer answer; |
3028 | 1638 uint16_t status; |
1639 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1640 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1641 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1642 0, NULL, NULL, NULL, 0, timeout_); |
3028 | 1643 |
1644 if (code == OrthancPluginErrorCode_Success) | |
1645 { | |
3320 | 1646 target.Swap(answer); |
3028 | 1647 return (status == 200); |
1648 } | |
1649 else | |
1650 { | |
1651 return false; | |
1652 } | |
1653 } | |
1654 | |
1655 | |
1656 bool OrthancPeers::DoGet(MemoryBuffer& target, | |
1657 const std::string& name, | |
1658 const std::string& uri) const | |
1659 { | |
1660 size_t index; | |
1661 return (LookupName(index, name) && | |
1662 DoGet(target, index, uri)); | |
1663 } | |
1664 | |
1665 | |
1666 bool OrthancPeers::DoGet(Json::Value& target, | |
1667 size_t index, | |
1668 const std::string& uri) const | |
1669 { | |
1670 MemoryBuffer buffer; | |
1671 | |
1672 if (DoGet(buffer, index, uri)) | |
1673 { | |
1674 buffer.ToJson(target); | |
1675 return true; | |
1676 } | |
1677 else | |
1678 { | |
1679 return false; | |
1680 } | |
1681 } | |
1682 | |
1683 | |
1684 bool OrthancPeers::DoGet(Json::Value& target, | |
1685 const std::string& name, | |
1686 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1687 { |
3028 | 1688 MemoryBuffer buffer; |
1689 | |
1690 if (DoGet(buffer, name, uri)) | |
1691 { | |
1692 buffer.ToJson(target); | |
1693 return true; | |
1694 } | |
1695 else | |
1696 { | |
1697 return false; | |
1698 } | |
1699 } | |
1700 | |
1701 | |
1702 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1703 const std::string& name, | |
1704 const std::string& uri, | |
1705 const std::string& body) const | |
1706 { | |
1707 size_t index; | |
1708 return (LookupName(index, name) && | |
1709 DoPost(target, index, uri, body)); | |
1710 } | |
1711 | |
1712 | |
1713 bool OrthancPeers::DoPost(Json::Value& target, | |
1714 size_t index, | |
1715 const std::string& uri, | |
1716 const std::string& body) const | |
1717 { | |
1718 MemoryBuffer buffer; | |
1719 | |
1720 if (DoPost(buffer, index, uri, body)) | |
1721 { | |
1722 buffer.ToJson(target); | |
1723 return true; | |
1724 } | |
1725 else | |
1726 { | |
1727 return false; | |
1728 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1729 } |
3028 | 1730 |
1731 | |
1732 bool OrthancPeers::DoPost(Json::Value& target, | |
1733 const std::string& name, | |
1734 const std::string& uri, | |
1735 const std::string& body) const | |
1736 { | |
1737 MemoryBuffer buffer; | |
1738 | |
1739 if (DoPost(buffer, name, uri, body)) | |
1740 { | |
1741 buffer.ToJson(target); | |
1742 return true; | |
1743 } | |
1744 else | |
1745 { | |
1746 return false; | |
1747 } | |
1748 } | |
1749 | |
1750 | |
1751 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1752 size_t index, | |
1753 const std::string& uri, | |
1754 const std::string& body) const | |
1755 { | |
1756 if (index >= index_.size()) | |
1757 { | |
1758 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1759 } | |
1760 | |
3320 | 1761 OrthancPlugins::MemoryBuffer answer; |
3028 | 1762 uint16_t status; |
1763 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1764 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1765 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1766 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3028 | 1767 |
1768 if (code == OrthancPluginErrorCode_Success) | |
1769 { | |
3320 | 1770 target.Swap(answer); |
3028 | 1771 return (status == 200); |
1772 } | |
1773 else | |
1774 { | |
1775 return false; | |
1776 } | |
1777 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1778 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1779 |
3028 | 1780 bool OrthancPeers::DoPut(size_t index, |
1781 const std::string& uri, | |
1782 const std::string& body) const | |
1783 { | |
1784 if (index >= index_.size()) | |
1785 { | |
1786 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1787 } | |
1788 | |
3320 | 1789 OrthancPlugins::MemoryBuffer answer; |
3028 | 1790 uint16_t status; |
1791 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1792 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1793 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1794 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3026 | 1795 |
3028 | 1796 if (code == OrthancPluginErrorCode_Success) |
1797 { | |
1798 return (status == 200); | |
1799 } | |
1800 else | |
1801 { | |
1802 return false; | |
1803 } | |
1804 } | |
1805 | |
1806 | |
1807 bool OrthancPeers::DoPut(const std::string& name, | |
1808 const std::string& uri, | |
1809 const std::string& body) const | |
1810 { | |
1811 size_t index; | |
1812 return (LookupName(index, name) && | |
1813 DoPut(index, uri, body)); | |
1814 } | |
1815 | |
1816 | |
1817 bool OrthancPeers::DoDelete(size_t index, | |
1818 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1819 { |
3028 | 1820 if (index >= index_.size()) |
1821 { | |
1822 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1823 } | |
1824 | |
3320 | 1825 OrthancPlugins::MemoryBuffer answer; |
3028 | 1826 uint16_t status; |
1827 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3320 | 1828 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1829 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | |
1830 0, NULL, NULL, NULL, 0, timeout_); | |
3028 | 1831 |
1832 if (code == OrthancPluginErrorCode_Success) | |
1833 { | |
1834 return (status == 200); | |
1835 } | |
1836 else | |
1837 { | |
1838 return false; | |
1839 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1840 } |
3028 | 1841 |
1842 | |
1843 bool OrthancPeers::DoDelete(const std::string& name, | |
1844 const std::string& uri) const | |
3026 | 1845 { |
3028 | 1846 size_t index; |
1847 return (LookupName(index, name) && | |
1848 DoDelete(index, uri)); | |
1849 } | |
1850 #endif | |
1851 | |
1852 | |
1853 | |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1854 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1855 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1856 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1857 ** JOBS |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1858 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
1859 |
3028 | 1860 #if HAS_ORTHANC_PLUGIN_JOB == 1 |
1861 void OrthancJob::CallbackFinalize(void* job) | |
1862 { | |
1863 if (job != NULL) | |
1864 { | |
1865 delete reinterpret_cast<OrthancJob*>(job); | |
1866 } | |
3026 | 1867 } |
3028 | 1868 |
1869 | |
1870 float OrthancJob::CallbackGetProgress(void* job) | |
1871 { | |
1872 assert(job != NULL); | |
1873 | |
1874 try | |
1875 { | |
1876 return reinterpret_cast<OrthancJob*>(job)->progress_; | |
1877 } | |
1878 catch (...) | |
1879 { | |
1880 return 0; | |
1881 } | |
1882 } | |
1883 | |
1884 | |
1885 const char* OrthancJob::CallbackGetContent(void* job) | |
1886 { | |
1887 assert(job != NULL); | |
1888 | |
1889 try | |
1890 { | |
1891 return reinterpret_cast<OrthancJob*>(job)->content_.c_str(); | |
1892 } | |
1893 catch (...) | |
1894 { | |
1895 return 0; | |
1896 } | |
1897 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1898 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1899 |
3028 | 1900 const char* OrthancJob::CallbackGetSerialized(void* job) |
1901 { | |
1902 assert(job != NULL); | |
1903 | |
1904 try | |
1905 { | |
1906 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job); | |
1907 | |
1908 if (tmp.hasSerialized_) | |
1909 { | |
1910 return tmp.serialized_.c_str(); | |
1911 } | |
1912 else | |
1913 { | |
1914 return NULL; | |
1915 } | |
1916 } | |
1917 catch (...) | |
1918 { | |
1919 return 0; | |
1920 } | |
1921 } | |
1922 | |
1923 | |
1924 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | |
1925 { | |
1926 assert(job != NULL); | |
1927 | |
1928 try | |
1929 { | |
1930 return reinterpret_cast<OrthancJob*>(job)->Step(); | |
1931 } | |
1932 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) | |
1933 { | |
1934 return OrthancPluginJobStepStatus_Failure; | |
1935 } | |
1936 catch (...) | |
1937 { | |
1938 return OrthancPluginJobStepStatus_Failure; | |
1939 } | |
1940 } | |
1941 | |
1942 | |
1943 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, | |
1944 OrthancPluginJobStopReason reason) | |
1945 { | |
1946 assert(job != NULL); | |
1947 | |
1948 try | |
1949 { | |
1950 reinterpret_cast<OrthancJob*>(job)->Stop(reason); | |
1951 return OrthancPluginErrorCode_Success; | |
1952 } | |
1953 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1954 { | |
1955 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1956 } | |
1957 catch (...) | |
1958 { | |
1959 return OrthancPluginErrorCode_Plugin; | |
1960 } | |
1961 } | |
1962 | |
1963 | |
1964 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1965 { |
3028 | 1966 assert(job != NULL); |
1967 | |
1968 try | |
1969 { | |
1970 reinterpret_cast<OrthancJob*>(job)->Reset(); | |
1971 return OrthancPluginErrorCode_Success; | |
1972 } | |
1973 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1974 { | |
1975 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1976 } | |
1977 catch (...) | |
1978 { | |
1979 return OrthancPluginErrorCode_Plugin; | |
1980 } | |
1981 } | |
1982 | |
1983 | |
1984 void OrthancJob::ClearContent() | |
1985 { | |
1986 Json::Value empty = Json::objectValue; | |
1987 UpdateContent(empty); | |
1988 } | |
1989 | |
1990 | |
1991 void OrthancJob::UpdateContent(const Json::Value& content) | |
1992 { | |
1993 if (content.type() != Json::objectValue) | |
1994 { | |
1995 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
1996 } | |
1997 else | |
1998 { | |
1999 Json::FastWriter writer; | |
2000 content_ = writer.write(content); | |
2001 } | |
2002 } | |
2003 | |
2004 | |
2005 void OrthancJob::ClearSerialized() | |
2006 { | |
2007 hasSerialized_ = false; | |
2008 serialized_.clear(); | |
3026 | 2009 } |
3028 | 2010 |
2011 | |
2012 void OrthancJob::UpdateSerialized(const Json::Value& serialized) | |
2013 { | |
2014 if (serialized.type() != Json::objectValue) | |
2015 { | |
2016 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
2017 } | |
2018 else | |
2019 { | |
2020 Json::FastWriter writer; | |
2021 serialized_ = writer.write(serialized); | |
2022 hasSerialized_ = true; | |
2023 } | |
2024 } | |
2025 | |
2026 | |
2027 void OrthancJob::UpdateProgress(float progress) | |
3026 | 2028 { |
3028 | 2029 if (progress < 0 || |
2030 progress > 1) | |
2031 { | |
2032 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2033 } | |
2034 | |
2035 progress_ = progress; | |
2036 } | |
2037 | |
2038 | |
2039 OrthancJob::OrthancJob(const std::string& jobType) : | |
2040 jobType_(jobType), | |
2041 progress_(0) | |
2042 { | |
2043 ClearContent(); | |
2044 ClearSerialized(); | |
2045 } | |
2046 | |
2047 | |
2048 OrthancPluginJob* OrthancJob::Create(OrthancJob* job) | |
2049 { | |
2050 if (job == NULL) | |
2051 { | |
2052 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | |
2053 } | |
2054 | |
2055 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2056 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2057 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2058 CallbackStep, CallbackStop, CallbackReset); |
3028 | 2059 |
2060 if (orthanc == NULL) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2061 { |
3026 | 2062 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2063 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2064 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2065 { |
3028 | 2066 return orthanc; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2067 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2068 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
2069 |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2070 |
3028 | 2071 std::string OrthancJob::Submit(OrthancJob* job, |
2072 int priority) | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2073 { |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2074 if (job == NULL) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2075 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2076 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2077 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2078 |
3028 | 2079 OrthancPluginJob* orthanc = Create(job); |
2080 | |
2081 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); | |
2082 | |
2083 if (id == NULL) | |
3026 | 2084 { |
3028 | 2085 LogError("Plugin cannot submit job"); |
2086 OrthancPluginFreeJob(GetGlobalContext(), orthanc); | |
3026 | 2087 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2088 } | |
2089 else | |
2090 { | |
3028 | 2091 std::string tmp(id); |
2092 tmp.assign(id); | |
2093 OrthancPluginFreeString(GetGlobalContext(), id); | |
3026 | 2094 |
3028 | 2095 return tmp; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2096 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2097 } |
3437
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2098 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2099 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2100 void OrthancJob::SubmitAndWait(Json::Value& result, |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2101 OrthancJob* job /* takes ownership */, |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2102 int priority) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2103 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2104 std::string id = Submit(job, priority); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2105 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2106 for (;;) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2107 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2108 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2109 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2110 Json::Value status; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2111 if (!RestApiGet(status, "/jobs/" + id, false) || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2112 !status.isMember("State") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2113 status["State"].type() != Json::stringValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2114 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2115 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2116 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2117 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2118 const std::string state = status["State"].asString(); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2119 if (state == "Success") |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2120 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2121 if (status.isMember("Content")) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2122 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2123 result = status["Content"]; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2124 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2125 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2126 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2127 result = Json::objectValue; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2128 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2129 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2130 return; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2131 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2132 else if (state == "Running") |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2133 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2134 continue; |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2135 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2136 else if (!status.isMember("ErrorCode") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2137 status["ErrorCode"].type() != Json::intValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2138 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2139 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2140 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2141 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2142 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2143 if (!status.isMember("ErrorDescription") || |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2144 status["ErrorDescription"].type() != Json::stringValue) |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2145 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2146 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2147 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2148 else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2149 { |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2150 #if HAS_ORTHANC_EXCEPTION == 1 |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2151 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()), |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2152 status["ErrorDescription"].asString()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2153 #else |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2154 LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2155 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2156 #endif |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2157 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2158 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2159 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2160 } |
dbaf439c8888
OrthancPlugins::OrthancJob::SubmitAndWait()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3434
diff
changeset
|
2161 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2162 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2163 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2164 const Json::Value& body, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2165 OrthancJob* job) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2166 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2167 static const char* KEY_SYNCHRONOUS = "Synchronous"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2168 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2169 static const char* KEY_PRIORITY = "Priority"; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2170 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2171 std::auto_ptr<OrthancJob> protection(job); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2172 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2173 if (body.type() != Json::objectValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2174 { |
3669 | 2175 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2176 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2177 "Expected a JSON object in the body"); |
3669 | 2178 #else |
2179 LogError("Expected a JSON object in the body"); | |
2180 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2181 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2182 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2183 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2184 bool synchronous = true; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2185 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2186 if (body.isMember(KEY_SYNCHRONOUS)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2187 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2188 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2189 { |
3669 | 2190 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2191 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2192 "Option \"" + std::string(KEY_SYNCHRONOUS) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2193 "\" must be Boolean"); |
3669 | 2194 #else |
2195 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); | |
2196 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2197 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2198 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2199 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2200 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2201 synchronous = body[KEY_SYNCHRONOUS].asBool(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2202 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2203 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2204 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2205 if (body.isMember(KEY_ASYNCHRONOUS)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2206 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2207 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2208 { |
3669 | 2209 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2210 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2211 "Option \"" + std::string(KEY_ASYNCHRONOUS) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2212 "\" must be Boolean"); |
3669 | 2213 #else |
2214 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); | |
2215 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2216 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2217 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2218 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2219 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2220 synchronous = !body[KEY_ASYNCHRONOUS].asBool(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2221 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2222 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2223 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2224 int priority = 0; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2225 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2226 if (body.isMember(KEY_PRIORITY)) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2227 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2228 if (body[KEY_PRIORITY].type() != Json::booleanValue) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2229 { |
3669 | 2230 #if HAS_ORTHANC_EXCEPTION == 1 |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2231 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2232 "Option \"" + std::string(KEY_PRIORITY) + |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2233 "\" must be an integer"); |
3669 | 2234 #else |
2235 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); | |
2236 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2237 #endif | |
3667
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2238 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2239 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2240 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2241 priority = !body[KEY_PRIORITY].asInt(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2242 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2243 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2244 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2245 Json::Value result; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2246 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2247 if (synchronous) |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2248 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2249 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2250 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2251 else |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2252 { |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2253 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2254 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2255 result = Json::objectValue; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2256 result["ID"] = id; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2257 result["Path"] = "/jobs/" + id; |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2258 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2259 |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2260 std::string s = result.toStyledString(); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2261 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2262 s.size(), "application/json"); |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2263 } |
c8d8c3b5f47c
OrthancJob::SubmitFromRestApiPost()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
2264 |
2817
473bf302d629
C++ wrappers around OrthancPluginJob and OrthancPluginPeers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2803
diff
changeset
|
2265 #endif |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2266 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2267 |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2268 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2269 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2270 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2271 ** METRICS |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2272 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2273 |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2274 #if HAS_ORTHANC_PLUGIN_METRICS == 1 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2275 MetricsTimer::MetricsTimer(const char* name) : |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2276 name_(name) |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2277 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2278 start_ = boost::posix_time::microsec_clock::universal_time(); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2279 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2280 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2281 MetricsTimer::~MetricsTimer() |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2282 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2283 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time(); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2284 const boost::posix_time::time_duration diff = stop - start_; |
3418 | 2285 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()), |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2286 OrthancPluginMetricsType_Timer); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2287 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2288 #endif |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2289 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2290 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2291 |
3397
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2292 |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2293 /****************************************************************** |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2294 ** HTTP CLIENT |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2295 ******************************************************************/ |
9019279dbfd7
new plugin c++ wrapper: MultipartRestCallback
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3394
diff
changeset
|
2296 |
3388 | 2297 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2298 class HttpClient::RequestBodyWrapper : public boost::noncopyable |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2299 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2300 private: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2301 static RequestBodyWrapper& GetObject(void* body) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2302 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2303 assert(body != NULL); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2304 return *reinterpret_cast<RequestBodyWrapper*>(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2305 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2306 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2307 IRequestBody& body_; |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2308 bool done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2309 std::string chunk_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2310 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2311 public: |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2312 RequestBodyWrapper(IRequestBody& body) : |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2313 body_(body), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2314 done_(false) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2315 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2316 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2317 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2318 static uint8_t IsDone(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2319 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2320 return GetObject(body).done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2321 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2322 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2323 static const void* GetChunkData(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2324 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2325 return GetObject(body).chunk_.c_str(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2326 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2327 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2328 static uint32_t GetChunkSize(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2329 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2330 return static_cast<uint32_t>(GetObject(body).chunk_.size()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2331 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2332 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2333 static OrthancPluginErrorCode Next(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2334 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2335 RequestBodyWrapper& that = GetObject(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2336 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2337 if (that.done_) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2338 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2339 return OrthancPluginErrorCode_BadSequenceOfCalls; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2340 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2341 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2342 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2343 try |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2344 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2345 that.done_ = !that.body_.ReadNextChunk(that.chunk_); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2346 return OrthancPluginErrorCode_Success; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2347 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2348 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2349 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2350 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2351 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2352 catch (...) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2353 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2354 return OrthancPluginErrorCode_InternalError; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2355 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2356 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2357 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2358 }; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2359 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2360 |
3413 | 2361 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2362 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2363 const char* key, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2364 const char* value) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2365 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2366 assert(answer != NULL && key != NULL && value != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2367 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2368 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2369 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2370 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2371 return OrthancPluginErrorCode_Success; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2372 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2373 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2374 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2375 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2376 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2377 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2378 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2379 return OrthancPluginErrorCode_Plugin; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2380 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2381 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2382 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2383 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2384 |
3413 | 2385 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2386 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2387 const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2388 uint32_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2389 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2390 assert(answer != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2391 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2392 try |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2393 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2394 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2395 return OrthancPluginErrorCode_Success; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2396 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2397 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2398 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2399 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2400 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2401 catch (...) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2402 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2403 return OrthancPluginErrorCode_Plugin; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2404 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2405 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2406 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2407 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2408 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2409 HttpClient::HttpClient() : |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2410 httpStatus_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2411 method_(OrthancPluginHttpMethod_Get), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2412 timeout_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2413 pkcs11_(false), |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2414 chunkedBody_(NULL), |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2415 allowChunkedTransfers_(true) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2416 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2417 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2418 |
3426
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2419 |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2420 void HttpClient::AddHeaders(const HttpHeaders& headers) |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2421 { |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2422 for (HttpHeaders::const_iterator it = headers.begin(); |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2423 it != headers.end(); ++it) |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2424 { |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2425 headers_[it->first] = it->second; |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2426 } |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2427 } |
00737cd21f40
OrthancPlugins::HttpClient::AddHeaders()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3422
diff
changeset
|
2428 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2429 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2430 void HttpClient::SetCredentials(const std::string& username, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2431 const std::string& password) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2432 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2433 username_ = username; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2434 password_ = password; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2435 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2436 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2437 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2438 void HttpClient::ClearCredentials() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2439 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2440 username_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2441 password_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2442 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2443 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2444 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2445 void HttpClient::SetCertificate(const std::string& certificateFile, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2446 const std::string& keyFile, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2447 const std::string& keyPassword) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2448 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2449 certificateFile_ = certificateFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2450 certificateKeyFile_ = keyFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2451 certificateKeyPassword_ = keyPassword; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2452 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2453 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2454 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2455 void HttpClient::ClearCertificate() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2456 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2457 certificateFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2458 certificateKeyFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2459 certificateKeyPassword_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2460 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2461 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2462 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2463 void HttpClient::ClearBody() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2464 { |
3413 | 2465 fullBody_.clear(); |
2466 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2467 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2468 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2469 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2470 void HttpClient::SwapBody(std::string& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2471 { |
3413 | 2472 fullBody_.swap(body); |
2473 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2474 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2475 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2476 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2477 void HttpClient::SetBody(const std::string& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2478 { |
3413 | 2479 fullBody_ = body; |
2480 chunkedBody_ = NULL; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2481 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2482 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2483 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2484 void HttpClient::SetBody(IRequestBody& body) |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2485 { |
3413 | 2486 fullBody_.clear(); |
2487 chunkedBody_ = &body; | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2488 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2489 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2490 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2491 namespace |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2492 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2493 class HeadersWrapper : public boost::noncopyable |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2494 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2495 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2496 std::vector<const char*> headersKeys_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2497 std::vector<const char*> headersValues_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2498 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2499 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2500 HeadersWrapper(const HttpClient::HttpHeaders& headers) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2501 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2502 headersKeys_.reserve(headers.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2503 headersValues_.reserve(headers.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2504 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2505 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2506 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2507 headersKeys_.push_back(it->first.c_str()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2508 headersValues_.push_back(it->second.c_str()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2509 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2510 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2511 |
3394 | 2512 void AddStaticString(const char* key, |
2513 const char* value) | |
2514 { | |
2515 headersKeys_.push_back(key); | |
2516 headersValues_.push_back(value); | |
2517 } | |
2518 | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2519 uint32_t GetCount() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2520 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2521 return headersKeys_.size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2522 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2523 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2524 const char* const* GetKeys() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2525 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2526 return headersKeys_.empty() ? NULL : &headersKeys_[0]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2527 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2528 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2529 const char* const* GetValues() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2530 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2531 return headersValues_.empty() ? NULL : &headersValues_[0]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2532 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2533 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2534 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2535 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2536 class MemoryRequestBody : public HttpClient::IRequestBody |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2537 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2538 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2539 std::string body_; |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2540 bool done_; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2541 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2542 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2543 MemoryRequestBody(const std::string& body) : |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2544 body_(body), |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2545 done_(false) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2546 { |
3434 | 2547 if (body_.empty()) |
2548 { | |
2549 done_ = true; | |
2550 } | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2551 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2552 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2553 virtual bool ReadNextChunk(std::string& chunk) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2554 { |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2555 if (done_) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2556 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2557 return false; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2558 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2559 else |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2560 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2561 chunk.swap(body_); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2562 done_ = true; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2563 return true; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2564 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2565 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2566 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2567 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2568 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2569 // This class mimics Orthanc::ChunkedBuffer |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2570 class ChunkedBuffer : public boost::noncopyable |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2571 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2572 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2573 typedef std::list<std::string*> Content; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2574 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2575 Content content_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2576 size_t size_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2577 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2578 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2579 ChunkedBuffer() : |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2580 size_(0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2581 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2582 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2583 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2584 ~ChunkedBuffer() |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2585 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2586 Clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2587 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2588 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2589 void Clear() |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2590 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2591 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2592 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2593 assert(*it != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2594 delete *it; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2595 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2596 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2597 content_.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2598 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2599 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2600 void Flatten(std::string& target) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2601 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2602 target.resize(size_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2603 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2604 size_t pos = 0; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2605 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2606 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2607 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2608 assert(*it != NULL); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2609 size_t s = (*it)->size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2610 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2611 if (s != 0) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2612 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2613 memcpy(&target[pos], (*it)->c_str(), s); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2614 pos += s; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2615 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2616 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2617 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2618 assert(size_ == 0 || |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2619 pos == target.size()); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2620 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2621 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2622 void AddChunk(const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2623 size_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2624 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2625 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2626 size_ += size; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2627 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2628 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2629 void AddChunk(const std::string& chunk) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2630 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2631 content_.push_back(new std::string(chunk)); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2632 size_ += chunk.size(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2633 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2634 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2635 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2636 |
3413 | 2637 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2638 class MemoryAnswer : public HttpClient::IAnswer |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2639 { |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2640 private: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2641 HttpClient::HttpHeaders headers_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2642 ChunkedBuffer body_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2643 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2644 public: |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2645 const HttpClient::HttpHeaders& GetHeaders() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2646 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2647 return headers_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2648 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2649 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2650 const ChunkedBuffer& GetBody() const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2651 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2652 return body_; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2653 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2654 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2655 virtual void AddHeader(const std::string& key, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2656 const std::string& value) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2657 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2658 headers_[key] = value; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2659 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2660 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2661 virtual void AddChunk(const void* data, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2662 size_t size) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2663 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2664 body_.AddChunk(data, size); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2665 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2666 }; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2667 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2668 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2669 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2670 |
3413 | 2671 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2672 void HttpClient::ExecuteWithStream(uint16_t& httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2673 IAnswer& answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2674 IRequestBody& body) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2675 { |
3394 | 2676 HeadersWrapper h(headers_); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2677 |
3434 | 2678 if (method_ == OrthancPluginHttpMethod_Post || |
2679 method_ == OrthancPluginHttpMethod_Put) | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2680 { |
3434 | 2681 // Automatically set the "Transfer-Encoding" header if absent |
2682 bool found = false; | |
2683 | |
2684 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) | |
3394 | 2685 { |
3434 | 2686 if (boost::iequals(it->first, "Transfer-Encoding")) |
2687 { | |
2688 found = true; | |
2689 break; | |
2690 } | |
3394 | 2691 } |
3434 | 2692 |
2693 if (!found) | |
2694 { | |
2695 h.AddStaticString("Transfer-Encoding", "chunked"); | |
2696 } | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2697 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2698 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2699 RequestBodyWrapper request(body); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2700 |
3413 | 2701 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2702 GetGlobalContext(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2703 &answer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2704 AnswerAddChunkCallback, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2705 AnswerAddHeaderCallback, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2706 &httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2707 method_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2708 url_.c_str(), |
3394 | 2709 h.GetCount(), |
2710 h.GetKeys(), | |
2711 h.GetValues(), | |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2712 &request, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2713 RequestBodyWrapper::IsDone, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2714 RequestBodyWrapper::GetChunkData, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2715 RequestBodyWrapper::GetChunkSize, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2716 RequestBodyWrapper::Next, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2717 username_.empty() ? NULL : username_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2718 password_.empty() ? NULL : password_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2719 timeout_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2720 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2721 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2722 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2723 pkcs11_ ? 1 : 0); |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2724 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2725 if (error != OrthancPluginErrorCode_Success) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2726 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2727 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2728 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2729 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2730 #endif |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2731 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2732 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2733 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2734 HttpHeaders& answerHeaders, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2735 std::string& answerBody, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2736 const std::string& body) const |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2737 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2738 HeadersWrapper headers(headers_); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2739 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2740 MemoryBuffer answerBodyBuffer, answerHeadersBuffer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2741 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2742 OrthancPluginErrorCode error = OrthancPluginHttpClient( |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2743 GetGlobalContext(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2744 *answerBodyBuffer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2745 *answerHeadersBuffer, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2746 &httpStatus, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2747 method_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2748 url_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2749 headers.GetCount(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2750 headers.GetKeys(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2751 headers.GetValues(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2752 body.empty() ? NULL : body.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2753 body.size(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2754 username_.empty() ? NULL : username_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2755 password_.empty() ? NULL : password_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2756 timeout_, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2757 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2758 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2759 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2760 pkcs11_ ? 1 : 0); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2761 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2762 if (error != OrthancPluginErrorCode_Success) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2763 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2764 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2765 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2766 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2767 Json::Value v; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2768 answerHeadersBuffer.ToJson(v); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2769 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2770 if (v.type() != Json::objectValue) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2771 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2772 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2773 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2774 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2775 Json::Value::Members members = v.getMemberNames(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2776 answerHeaders.clear(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2777 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2778 for (size_t i = 0; i < members.size(); i++) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2779 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2780 const Json::Value& h = v[members[i]]; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2781 if (h.type() != Json::stringValue) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2782 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2783 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2784 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2785 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2786 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2787 answerHeaders[members[i]] = h.asString(); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2788 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2789 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2790 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2791 answerBodyBuffer.ToString(answerBody); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2792 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2793 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2794 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2795 void HttpClient::Execute(IAnswer& answer) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2796 { |
3438
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2797 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2798 if (allowChunkedTransfers_) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2799 { |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2800 if (chunkedBody_ != NULL) |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2801 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2802 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2803 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2804 else |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2805 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2806 MemoryRequestBody wrapper(fullBody_); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2807 ExecuteWithStream(httpStatus_, answer, wrapper); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2808 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2809 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2810 return; |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2811 } |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2812 #endif |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2813 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2814 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2815 // transfers are disabled. This results in higher memory usage |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2816 // (all chunks from the answer body are sent at once) |
3438
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2817 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2818 HttpHeaders answerHeaders; |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2819 std::string answerBody; |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2820 Execute(answerHeaders, answerBody); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2821 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2822 for (HttpHeaders::const_iterator it = answerHeaders.begin(); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2823 it != answerHeaders.end(); ++it) |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2824 { |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2825 answer.AddHeader(it->first, it->second); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2826 } |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2827 |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2828 if (!answerBody.empty()) |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2829 { |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2830 answer.AddChunk(answerBody.c_str(), answerBody.size()); |
d97ef941d521
compatibility mode for OrthancPlugins::HttpClient::IAnswer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3437
diff
changeset
|
2831 } |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2832 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2833 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2834 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2835 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2836 std::string& answerBody /* out */) |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2837 { |
3413 | 2838 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 |
3443
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2839 if (allowChunkedTransfers_) |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2840 { |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2841 MemoryAnswer answer; |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2842 Execute(answer); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2843 answerHeaders = answer.GetHeaders(); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2844 answer.GetBody().Flatten(answerBody); |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2845 return; |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2846 } |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2847 #endif |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2848 |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2849 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2850 // transfers are disabled. This results in higher memory usage |
0371b65d5f76
OrthancPlugins::HttpClient::SetChunkedTransfersAllowed()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3440
diff
changeset
|
2851 // (all chunks from the request body are sent at once) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2852 |
3413 | 2853 if (chunkedBody_ != NULL) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2854 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2855 ChunkedBuffer buffer; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2856 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2857 std::string chunk; |
3413 | 2858 while (chunkedBody_->ReadNextChunk(chunk)) |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2859 { |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2860 buffer.AddChunk(chunk); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2861 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2862 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2863 std::string body; |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2864 buffer.Flatten(body); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2865 |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2866 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body); |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2867 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2868 else |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2869 { |
3413 | 2870 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); |
3393
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2871 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2872 } |
2cd0369a156f
support of chunked answers in HttpClient and in SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3392
diff
changeset
|
2873 |
3420
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2874 |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2875 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2876 Json::Value& answerBody /* out */) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2877 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2878 std::string body; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2879 Execute(answerHeaders, body); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2880 |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2881 Json::Reader reader; |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2882 if (!reader.parse(body, answerBody)) |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2883 { |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2884 LogError("Cannot convert HTTP answer body to JSON"); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2885 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2886 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2887 } |
0a0e7eca95ae
fix encoding in DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3418
diff
changeset
|
2888 |
3434 | 2889 |
2890 void HttpClient::Execute() | |
2891 { | |
2892 HttpHeaders answerHeaders; | |
2893 std::string body; | |
2894 Execute(answerHeaders, body); | |
2895 } | |
2896 | |
3388 | 2897 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ |
3416 | 2898 |
2899 | |
2900 | |
2901 | |
2902 | |
2903 /****************************************************************** | |
2904 ** CHUNKED HTTP SERVER | |
2905 ******************************************************************/ | |
2906 | |
2907 namespace Internals | |
2908 { | |
2909 void NullRestCallback(OrthancPluginRestOutput* output, | |
2910 const char* url, | |
2911 const OrthancPluginHttpRequest* request) | |
2912 { | |
2913 } | |
2914 | |
2915 IChunkedRequestReader *NullChunkedRestCallback(const char* url, | |
2916 const OrthancPluginHttpRequest* request) | |
2917 { | |
2918 return NULL; | |
2919 } | |
2920 | |
2921 | |
2922 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 | |
2923 | |
2924 OrthancPluginErrorCode ChunkedRequestReaderAddChunk( | |
2925 OrthancPluginServerChunkedRequestReader* reader, | |
2926 const void* data, | |
2927 uint32_t size) | |
2928 { | |
2929 try | |
2930 { | |
2931 if (reader == NULL) | |
2932 { | |
2933 return OrthancPluginErrorCode_InternalError; | |
2934 } | |
2935 | |
2936 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size); | |
2937 return OrthancPluginErrorCode_Success; | |
2938 } | |
2939 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2940 { | |
2941 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2942 } | |
2943 catch (boost::bad_lexical_cast&) | |
2944 { | |
2945 return OrthancPluginErrorCode_BadFileFormat; | |
2946 } | |
2947 catch (...) | |
2948 { | |
2949 return OrthancPluginErrorCode_Plugin; | |
2950 } | |
2951 } | |
2952 | |
2953 | |
2954 OrthancPluginErrorCode ChunkedRequestReaderExecute( | |
2955 OrthancPluginServerChunkedRequestReader* reader, | |
2956 OrthancPluginRestOutput* output) | |
2957 { | |
2958 try | |
2959 { | |
2960 if (reader == NULL) | |
2961 { | |
2962 return OrthancPluginErrorCode_InternalError; | |
2963 } | |
2964 | |
2965 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output); | |
2966 return OrthancPluginErrorCode_Success; | |
2967 } | |
2968 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2969 { | |
2970 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2971 } | |
2972 catch (boost::bad_lexical_cast&) | |
2973 { | |
2974 return OrthancPluginErrorCode_BadFileFormat; | |
2975 } | |
2976 catch (...) | |
2977 { | |
2978 return OrthancPluginErrorCode_Plugin; | |
2979 } | |
2980 } | |
2981 | |
2982 | |
2983 void ChunkedRequestReaderFinalize( | |
2984 OrthancPluginServerChunkedRequestReader* reader) | |
2985 { | |
2986 if (reader != NULL) | |
2987 { | |
2988 delete reinterpret_cast<IChunkedRequestReader*>(reader); | |
2989 } | |
2990 } | |
2991 | |
2992 #else | |
2993 | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2994 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2995 const char* url, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2996 const OrthancPluginHttpRequest* request, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2997 RestCallback GetHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2998 ChunkedRestCallback PostHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
2999 RestCallback DeleteHandler, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3000 ChunkedRestCallback PutHandler) |
3416 | 3001 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3002 try |
3416 | 3003 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3004 std::string allowed; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3005 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3006 if (GetHandler != Internals::NullRestCallback) |
3416 | 3007 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3008 allowed += "GET"; |
3416 | 3009 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3010 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3011 if (PostHandler != Internals::NullChunkedRestCallback) |
3416 | 3012 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3013 if (!allowed.empty()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3014 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3015 allowed += ","; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3016 } |
3416 | 3017 |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3018 allowed += "POST"; |
3416 | 3019 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3020 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3021 if (DeleteHandler != Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3022 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3023 if (!allowed.empty()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3024 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3025 allowed += ","; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3026 } |
3416 | 3027 |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3028 allowed += "DELETE"; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3029 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3030 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3031 if (PutHandler != Internals::NullChunkedRestCallback) |
3416 | 3032 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3033 if (!allowed.empty()) |
3416 | 3034 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3035 allowed += ","; |
3416 | 3036 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3037 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3038 allowed += "PUT"; |
3416 | 3039 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3040 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3041 switch (request->method) |
3416 | 3042 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3043 case OrthancPluginHttpMethod_Get: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3044 if (GetHandler == Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3045 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3046 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3047 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3048 else |
3416 | 3049 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3050 GetHandler(output, url, request); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3051 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3052 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3053 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3054 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3055 case OrthancPluginHttpMethod_Post: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3056 if (PostHandler == Internals::NullChunkedRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3057 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3058 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
3416 | 3059 } |
3060 else | |
3061 { | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3062 std::auto_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3063 if (reader.get() == NULL) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3064 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3065 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3066 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3067 else |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3068 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3069 reader->AddChunk(request->body, request->bodySize); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3070 reader->Execute(output); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3071 } |
3416 | 3072 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3073 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3074 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3075 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3076 case OrthancPluginHttpMethod_Delete: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3077 if (DeleteHandler == Internals::NullRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3078 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3079 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3080 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3081 else |
3416 | 3082 { |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3083 DeleteHandler(output, url, request); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3084 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3085 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3086 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3087 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3088 case OrthancPluginHttpMethod_Put: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3089 if (PutHandler == Internals::NullChunkedRestCallback) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3090 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3091 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
3416 | 3092 } |
3093 else | |
3094 { | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3095 std::auto_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3096 if (reader.get() == NULL) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3097 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3098 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3099 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3100 else |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3101 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3102 reader->AddChunk(request->body, request->bodySize); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3103 reader->Execute(output); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3104 } |
3416 | 3105 } |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3106 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3107 break; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3108 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3109 default: |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3110 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
3416 | 3111 } |
3112 | |
3433
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3113 return OrthancPluginErrorCode_Success; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3114 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3115 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3116 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3117 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3118 if (HasGlobalContext() && |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3119 e.HasDetails()) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3120 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3121 // The "false" instructs Orthanc not to log the detailed |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3122 // error message. This is to avoid duplicating the details, |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3123 // because "OrthancException" already does it on construction. |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3124 OrthancPluginSetHttpErrorDetails |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3125 (GetGlobalContext(), output, e.GetDetails(), false); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3126 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3127 #endif |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3128 |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3129 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3130 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3131 catch (boost::bad_lexical_cast&) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3132 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3133 return OrthancPluginErrorCode_BadFileFormat; |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3134 } |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3135 catch (...) |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3136 { |
caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3426
diff
changeset
|
3137 return OrthancPluginErrorCode_Plugin; |
3416 | 3138 } |
3139 } | |
3140 #endif | |
3141 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3142 } |