Mercurial > hg > orthanc
annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3387:a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2019 17:17:48 +0200 |
parents | 0f721f015b85 |
children | 18cd4951fccc |
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 |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3039
diff
changeset
|
5 * Copyright (C) 2017-2019 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 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include <json/reader.h> |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
37 #include <json/writer.h> |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 namespace OrthancPlugins |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
3028 | 42 static OrthancPluginContext* globalContext_ = NULL; |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
43 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
44 |
3028 | 45 void SetGlobalContext(OrthancPluginContext* context) |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
46 { |
3028 | 47 if (context == NULL) |
48 { | |
49 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
50 } | |
51 else if (globalContext_ == NULL) | |
52 { | |
53 globalContext_ = context; | |
54 } | |
55 else | |
56 { | |
57 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
58 } | |
3026 | 59 } |
60 | |
61 | |
3028 | 62 bool HasGlobalContext() |
63 { | |
64 return globalContext_ != NULL; | |
65 } | |
66 | |
67 | |
68 OrthancPluginContext* GetGlobalContext() | |
69 { | |
70 if (globalContext_ == NULL) | |
71 { | |
72 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
73 } | |
74 else | |
75 { | |
76 return globalContext_; | |
77 } | |
78 } | |
2958
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
79 |
bb7a66efbeb1
OrthancPlugins::SetGlobalContext() in OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2851
diff
changeset
|
80 |
3028 | 81 void MemoryBuffer::Check(OrthancPluginErrorCode code) |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
82 { |
3028 | 83 if (code != OrthancPluginErrorCode_Success) |
84 { | |
85 // Prevent using garbage information | |
86 buffer_.data = NULL; | |
87 buffer_.size = 0; | |
88 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
89 } | |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
90 } |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
91 |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2059
diff
changeset
|
92 |
3028 | 93 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
|
94 { |
3028 | 95 if (code != OrthancPluginErrorCode_Success) |
96 { | |
97 // Prevent using garbage information | |
98 buffer_.data = NULL; | |
99 buffer_.size = 0; | |
100 } | |
101 | |
102 if (code == OrthancPluginErrorCode_Success) | |
103 { | |
104 return true; | |
105 } | |
106 else if (code == OrthancPluginErrorCode_UnknownResource || | |
107 code == OrthancPluginErrorCode_InexistentItem) | |
108 { | |
109 return false; | |
110 } | |
111 else | |
112 { | |
113 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
114 } | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
115 } |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
116 |
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
117 |
3028 | 118 MemoryBuffer::MemoryBuffer() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 buffer_.data = NULL; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 buffer_.size = 0; |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 |
3028 | 124 |
125 void MemoryBuffer::Clear() | |
3026 | 126 { |
3028 | 127 if (buffer_.data != NULL) |
128 { | |
129 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); | |
130 buffer_.data = NULL; | |
131 buffer_.size = 0; | |
132 } | |
3026 | 133 } |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
3026 | 135 |
3028 | 136 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) |
137 { | |
138 Clear(); | |
139 | |
140 buffer_.data = other.data; | |
141 buffer_.size = other.size; | |
142 | |
143 other.data = NULL; | |
144 other.size = 0; | |
145 } | |
3026 | 146 |
147 | |
3320 | 148 void MemoryBuffer::Swap(MemoryBuffer& other) |
149 { | |
150 std::swap(buffer_.data, other.buffer_.data); | |
151 std::swap(buffer_.size, other.buffer_.size); | |
152 } | |
153 | |
154 | |
3028 | 155 OrthancPluginMemoryBuffer MemoryBuffer::Release() |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
3028 | 157 OrthancPluginMemoryBuffer result = buffer_; |
158 | |
3026 | 159 buffer_.data = NULL; |
160 buffer_.size = 0; | |
3028 | 161 |
162 return result; | |
3026 | 163 } |
3028 | 164 |
165 | |
166 void MemoryBuffer::ToString(std::string& target) const | |
167 { | |
168 if (buffer_.size == 0) | |
169 { | |
170 target.clear(); | |
171 } | |
172 else | |
173 { | |
174 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size); | |
175 } | |
176 } | |
3026 | 177 |
178 | |
3028 | 179 void MemoryBuffer::ToJson(Json::Value& target) const |
180 { | |
181 if (buffer_.data == NULL || | |
182 buffer_.size == 0) | |
183 { | |
184 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
185 } | |
3026 | 186 |
3028 | 187 const char* tmp = reinterpret_cast<const char*>(buffer_.data); |
3026 | 188 |
3028 | 189 Json::Reader reader; |
190 if (!reader.parse(tmp, tmp + buffer_.size, target)) | |
191 { | |
192 LogError("Cannot convert some memory buffer to JSON"); | |
193 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
194 } | |
195 } | |
3026 | 196 |
197 | |
3028 | 198 bool MemoryBuffer::RestApiGet(const std::string& uri, |
199 bool applyPlugins) | |
3026 | 200 { |
3028 | 201 Clear(); |
3026 | 202 |
3028 | 203 if (applyPlugins) |
204 { | |
205 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); | |
206 } | |
207 else | |
208 { | |
209 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); | |
210 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 |
3028 | 213 bool MemoryBuffer::RestApiGet(const std::string& uri, |
214 const std::map<std::string, std::string>& httpHeaders, | |
215 bool applyPlugins) | |
3026 | 216 { |
3028 | 217 Clear(); |
218 | |
219 std::vector<const char*> headersKeys; | |
220 std::vector<const char*> headersValues; | |
3039 | 221 |
222 for (std::map<std::string, std::string>::const_iterator | |
223 it = httpHeaders.begin(); it != httpHeaders.end(); it++) | |
3028 | 224 { |
225 headersKeys.push_back(it->first.c_str()); | |
226 headersValues.push_back(it->second.c_str()); | |
227 } | |
228 | |
3039 | 229 return CheckHttp(OrthancPluginRestApiGet2( |
230 GetGlobalContext(), &buffer_, uri.c_str(), httpHeaders.size(), | |
231 (headersKeys.empty() ? NULL : &headersKeys[0]), | |
232 (headersValues.empty() ? NULL : &headersValues[0]), applyPlugins)); | |
3026 | 233 } |
3028 | 234 |
235 bool MemoryBuffer::RestApiPost(const std::string& uri, | |
236 const char* body, | |
237 size_t bodySize, | |
238 bool applyPlugins) | |
239 { | |
240 Clear(); | |
241 | |
242 if (applyPlugins) | |
243 { | |
244 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize)); | |
245 } | |
246 else | |
247 { | |
248 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize)); | |
249 } | |
250 } | |
3026 | 251 |
252 | |
3028 | 253 bool MemoryBuffer::RestApiPut(const std::string& uri, |
254 const char* body, | |
255 size_t bodySize, | |
256 bool applyPlugins) | |
257 { | |
258 Clear(); | |
3026 | 259 |
3028 | 260 if (applyPlugins) |
261 { | |
262 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize)); | |
263 } | |
264 else | |
265 { | |
266 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), body, bodySize)); | |
267 } | |
3026 | 268 } |
3028 | 269 |
3026 | 270 |
3028 | 271 bool MemoryBuffer::RestApiPost(const std::string& uri, |
272 const Json::Value& body, | |
273 bool applyPlugins) | |
3026 | 274 { |
3028 | 275 Json::FastWriter writer; |
276 return RestApiPost(uri, writer.write(body), applyPlugins); | |
3026 | 277 } |
278 | |
3028 | 279 |
280 bool MemoryBuffer::RestApiPut(const std::string& uri, | |
281 const Json::Value& body, | |
282 bool applyPlugins) | |
283 { | |
284 Json::FastWriter writer; | |
285 return RestApiPut(uri, writer.write(body), applyPlugins); | |
286 } | |
3026 | 287 |
3028 | 288 |
289 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
290 OrthancPluginCreateDicomFlags flags) | |
291 { | |
292 Clear(); | |
293 | |
294 Json::FastWriter writer; | |
295 std::string s = writer.write(tags); | |
3026 | 296 |
3028 | 297 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); |
3026 | 298 } |
3028 | 299 |
300 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
301 const OrthancImage& pixelData, | |
302 OrthancPluginCreateDicomFlags flags) | |
3026 | 303 { |
3028 | 304 Clear(); |
305 | |
306 Json::FastWriter writer; | |
307 std::string s = writer.write(tags); | |
308 | |
309 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); | |
3026 | 310 } |
3028 | 311 |
312 | |
313 void MemoryBuffer::ReadFile(const std::string& path) | |
314 { | |
315 Clear(); | |
316 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); | |
317 } | |
3026 | 318 |
319 | |
3028 | 320 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) |
3026 | 321 { |
3028 | 322 Clear(); |
323 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); | |
3026 | 324 } |
325 | |
326 | |
3028 | 327 void OrthancString::Assign(char* str) |
328 { | |
329 if (str == NULL) | |
330 { | |
331 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
332 } | |
333 else | |
334 { | |
335 Clear(); | |
336 str_ = str; | |
337 } | |
338 } | |
3026 | 339 |
340 | |
3028 | 341 void OrthancString::Clear() |
342 { | |
343 if (str_ != NULL) | |
344 { | |
345 OrthancPluginFreeString(GetGlobalContext(), str_); | |
346 str_ = NULL; | |
347 } | |
348 } | |
3026 | 349 |
350 | |
3028 | 351 void OrthancString::ToString(std::string& target) const |
352 { | |
353 if (str_ == NULL) | |
354 { | |
355 target.clear(); | |
356 } | |
357 else | |
358 { | |
359 target.assign(str_); | |
360 } | |
361 } | |
3026 | 362 |
363 | |
3028 | 364 void OrthancString::ToJson(Json::Value& target) const |
365 { | |
366 if (str_ == NULL) | |
367 { | |
368 LogError("Cannot convert an empty memory buffer to JSON"); | |
369 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
370 } | |
371 | |
372 Json::Reader reader; | |
373 if (!reader.parse(str_, target)) | |
374 { | |
375 LogError("Cannot convert some memory buffer to JSON"); | |
376 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
377 } | |
378 } | |
3026 | 379 |
380 | |
3028 | 381 void MemoryBuffer::DicomToJson(Json::Value& target, |
382 OrthancPluginDicomToJsonFormat format, | |
383 OrthancPluginDicomToJsonFlags flags, | |
384 uint32_t maxStringLength) | |
385 { | |
386 OrthancString str; | |
387 str.Assign(OrthancPluginDicomBufferToJson | |
388 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); | |
389 str.ToJson(target); | |
390 } | |
3026 | 391 |
392 | |
3028 | 393 bool MemoryBuffer::HttpGet(const std::string& url, |
394 const std::string& username, | |
395 const std::string& password) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 { |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 Clear(); |
3028 | 398 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), |
399 username.empty() ? NULL : username.c_str(), | |
400 password.empty() ? NULL : password.c_str())); | |
3026 | 401 } |
402 | |
403 | |
3028 | 404 bool MemoryBuffer::HttpPost(const std::string& url, |
405 const std::string& body, | |
406 const std::string& username, | |
407 const std::string& password) | |
3026 | 408 { |
3028 | 409 Clear(); |
410 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), | |
411 body.c_str(), body.size(), | |
412 username.empty() ? NULL : username.c_str(), | |
413 password.empty() ? NULL : password.c_str())); | |
3026 | 414 } |
415 | |
416 | |
3028 | 417 bool MemoryBuffer::HttpPut(const std::string& url, |
418 const std::string& body, | |
419 const std::string& username, | |
420 const std::string& password) | |
3026 | 421 { |
3028 | 422 Clear(); |
423 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), | |
424 body.empty() ? NULL : body.c_str(), | |
425 body.size(), | |
426 username.empty() ? NULL : username.c_str(), | |
427 password.empty() ? NULL : password.c_str())); | |
3026 | 428 } |
429 | |
3028 | 430 |
431 void MemoryBuffer::GetDicomInstance(const std::string& instanceId) | |
3026 | 432 { |
3028 | 433 Clear(); |
434 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); | |
3026 | 435 } |
436 | |
437 | |
3028 | 438 bool HttpDelete(const std::string& url, |
439 const std::string& username, | |
440 const std::string& password) | |
441 { | |
442 OrthancPluginErrorCode error = OrthancPluginHttpDelete | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
443 (GetGlobalContext(), url.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
444 username.empty() ? NULL : username.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
445 password.empty() ? NULL : password.c_str()); |
3028 | 446 |
447 if (error == OrthancPluginErrorCode_Success) | |
448 { | |
449 return true; | |
450 } | |
451 else if (error == OrthancPluginErrorCode_UnknownResource || | |
452 error == OrthancPluginErrorCode_InexistentItem) | |
453 { | |
454 return false; | |
455 } | |
456 else | |
457 { | |
458 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
459 } | |
460 } | |
3026 | 461 |
462 | |
3028 | 463 void LogError(const std::string& message) |
464 { | |
465 if (HasGlobalContext()) | |
466 { | |
467 OrthancPluginLogError(GetGlobalContext(), message.c_str()); | |
468 } | |
469 } | |
3026 | 470 |
471 | |
3028 | 472 void LogWarning(const std::string& message) |
473 { | |
474 if (HasGlobalContext()) | |
475 { | |
476 OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); | |
477 } | |
478 } | |
479 | |
480 | |
481 void LogInfo(const std::string& message) | |
482 { | |
483 if (HasGlobalContext()) | |
484 { | |
485 OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); | |
486 } | |
487 } | |
3026 | 488 |
489 | |
3028 | 490 OrthancConfiguration::OrthancConfiguration() |
491 { | |
492 OrthancString str; | |
493 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); | |
3026 | 494 |
3028 | 495 if (str.GetContent() == NULL) |
496 { | |
497 LogError("Cannot access the Orthanc configuration"); | |
498 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
499 } | |
3026 | 500 |
3028 | 501 str.ToJson(configuration_); |
502 | |
503 if (configuration_.type() != Json::objectValue) | |
504 { | |
505 LogError("Unable to read the Orthanc configuration"); | |
506 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
507 } | |
508 } | |
3026 | 509 |
510 | |
3028 | 511 std::string OrthancConfiguration::GetPath(const std::string& key) const |
3026 | 512 { |
3028 | 513 if (path_.empty()) |
514 { | |
515 return key; | |
516 } | |
517 else | |
518 { | |
519 return path_ + "." + key; | |
520 } | |
3026 | 521 } |
3028 | 522 |
523 | |
524 bool OrthancConfiguration::IsSection(const std::string& key) const | |
3026 | 525 { |
3028 | 526 assert(configuration_.type() == Json::objectValue); |
527 | |
528 return (configuration_.isMember(key) && | |
529 configuration_[key].type() == Json::objectValue); | |
3026 | 530 } |
531 | |
532 | |
3028 | 533 void OrthancConfiguration::GetSection(OrthancConfiguration& target, |
534 const std::string& key) const | |
3026 | 535 { |
3028 | 536 assert(configuration_.type() == Json::objectValue); |
3026 | 537 |
3028 | 538 target.path_ = GetPath(key); |
3026 | 539 |
3028 | 540 if (!configuration_.isMember(key)) |
541 { | |
542 target.configuration_ = Json::objectValue; | |
543 } | |
544 else | |
545 { | |
546 if (configuration_[key].type() != Json::objectValue) | |
547 { | |
548 LogError("The configuration section \"" + target.path_ + | |
549 "\" is not an associative array as expected"); | |
550 | |
551 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
552 } | |
553 | |
554 target.configuration_ = configuration_[key]; | |
555 } | |
3026 | 556 } |
557 | |
558 | |
3028 | 559 bool OrthancConfiguration::LookupStringValue(std::string& target, |
560 const std::string& key) const | |
561 { | |
562 assert(configuration_.type() == Json::objectValue); | |
563 | |
564 if (!configuration_.isMember(key)) | |
565 { | |
566 return false; | |
567 } | |
3026 | 568 |
3028 | 569 if (configuration_[key].type() != Json::stringValue) |
570 { | |
571 LogError("The configuration option \"" + GetPath(key) + | |
572 "\" is not a string as expected"); | |
573 | |
574 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
575 } | |
576 | |
577 target = configuration_[key].asString(); | |
578 return true; | |
3026 | 579 } |
580 | |
581 | |
3028 | 582 bool OrthancConfiguration::LookupIntegerValue(int& target, |
583 const std::string& key) const | |
3026 | 584 { |
3028 | 585 assert(configuration_.type() == Json::objectValue); |
586 | |
587 if (!configuration_.isMember(key)) | |
588 { | |
589 return false; | |
590 } | |
591 | |
592 switch (configuration_[key].type()) | |
593 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
594 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
595 target = configuration_[key].asInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
596 return true; |
3028 | 597 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
598 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
599 target = configuration_[key].asUInt(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
600 return true; |
3028 | 601 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
602 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
603 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
604 "\" is not an integer as expected"); |
3028 | 605 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
606 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 607 } |
3026 | 608 } |
609 | |
610 | |
3028 | 611 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, |
612 const std::string& key) const | |
613 { | |
614 int tmp; | |
615 if (!LookupIntegerValue(tmp, key)) | |
616 { | |
617 return false; | |
618 } | |
3026 | 619 |
3028 | 620 if (tmp < 0) |
621 { | |
622 LogError("The configuration option \"" + GetPath(key) + | |
623 "\" is not a positive integer as expected"); | |
624 | |
625 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
626 } | |
627 else | |
628 { | |
629 target = static_cast<unsigned int>(tmp); | |
630 return true; | |
631 } | |
632 } | |
3026 | 633 |
634 | |
3028 | 635 bool OrthancConfiguration::LookupBooleanValue(bool& target, |
636 const std::string& key) const | |
3026 | 637 { |
3028 | 638 assert(configuration_.type() == Json::objectValue); |
639 | |
640 if (!configuration_.isMember(key)) | |
3026 | 641 { |
3028 | 642 return false; |
643 } | |
644 | |
645 if (configuration_[key].type() != Json::booleanValue) | |
646 { | |
647 LogError("The configuration option \"" + GetPath(key) + | |
648 "\" is not a Boolean as expected"); | |
3026 | 649 |
650 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
651 } | |
652 | |
3028 | 653 target = configuration_[key].asBool(); |
654 return true; | |
3026 | 655 } |
3028 | 656 |
657 | |
658 bool OrthancConfiguration::LookupFloatValue(float& target, | |
659 const std::string& key) const | |
660 { | |
661 assert(configuration_.type() == Json::objectValue); | |
662 | |
663 if (!configuration_.isMember(key)) | |
664 { | |
665 return false; | |
666 } | |
667 | |
668 switch (configuration_[key].type()) | |
669 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
670 case Json::realValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
671 target = configuration_[key].asFloat(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
672 return true; |
3028 | 673 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
674 case Json::intValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
675 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
|
676 return true; |
3028 | 677 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
678 case Json::uintValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
679 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
|
680 return true; |
3028 | 681 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
682 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
683 LogError("The configuration option \"" + GetPath(key) + |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
684 "\" is not an integer as expected"); |
3028 | 685 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
686 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
3028 | 687 } |
688 } | |
3026 | 689 |
690 | |
3028 | 691 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
692 const std::string& key, | |
693 bool allowSingleString) const | |
3026 | 694 { |
3028 | 695 assert(configuration_.type() == Json::objectValue); |
696 | |
697 target.clear(); | |
698 | |
699 if (!configuration_.isMember(key)) | |
700 { | |
701 return false; | |
702 } | |
703 | |
704 switch (configuration_[key].type()) | |
705 { | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
706 case Json::arrayValue: |
3028 | 707 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
708 bool ok = true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
709 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
710 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
3028 | 711 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
712 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
|
713 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
714 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
|
715 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
716 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
717 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
718 ok = false; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
719 } |
3028 | 720 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
721 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
722 if (ok) |
3028 | 723 { |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
724 return true; |
3028 | 725 } |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
726 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
727 break; |
3028 | 728 } |
729 | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
730 case Json::stringValue: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
731 if (allowSingleString) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
732 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
733 target.push_back(configuration_[key].asString()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
734 return true; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
735 } |
3028 | 736 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
737 break; |
3028 | 738 |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
739 default: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
740 break; |
3028 | 741 } |
742 | |
3026 | 743 LogError("The configuration option \"" + GetPath(key) + |
3028 | 744 "\" is not a list of strings as expected"); |
3026 | 745 |
746 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
747 } | |
748 | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
749 |
3028 | 750 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target, |
751 const std::string& key, | |
752 bool allowSingleString) const | |
753 { | |
754 std::list<std::string> lst; | |
755 | |
756 if (LookupListOfStrings(lst, key, allowSingleString)) | |
757 { | |
758 target.clear(); | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
759 |
3028 | 760 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
|
761 it = lst.begin(); it != lst.end(); ++it) |
3028 | 762 { |
763 target.insert(*it); | |
764 } | |
3026 | 765 |
3028 | 766 return true; |
767 } | |
768 else | |
769 { | |
770 return false; | |
771 } | |
3026 | 772 } |
773 | |
3028 | 774 |
775 std::string OrthancConfiguration::GetStringValue(const std::string& key, | |
776 const std::string& defaultValue) const | |
3026 | 777 { |
3028 | 778 std::string tmp; |
779 if (LookupStringValue(tmp, key)) | |
780 { | |
781 return tmp; | |
782 } | |
783 else | |
784 { | |
785 return defaultValue; | |
786 } | |
3026 | 787 } |
788 | |
789 | |
3028 | 790 int OrthancConfiguration::GetIntegerValue(const std::string& key, |
791 int defaultValue) const | |
3026 | 792 { |
3028 | 793 int tmp; |
794 if (LookupIntegerValue(tmp, key)) | |
795 { | |
796 return tmp; | |
797 } | |
798 else | |
799 { | |
800 return defaultValue; | |
801 } | |
3026 | 802 } |
803 | |
3028 | 804 |
805 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, | |
806 unsigned int defaultValue) const | |
3026 | 807 { |
3028 | 808 unsigned int tmp; |
809 if (LookupUnsignedIntegerValue(tmp, key)) | |
810 { | |
811 return tmp; | |
812 } | |
813 else | |
814 { | |
815 return defaultValue; | |
816 } | |
3026 | 817 } |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
818 |
3026 | 819 |
3028 | 820 bool OrthancConfiguration::GetBooleanValue(const std::string& key, |
821 bool defaultValue) const | |
3026 | 822 { |
3028 | 823 bool tmp; |
824 if (LookupBooleanValue(tmp, key)) | |
825 { | |
826 return tmp; | |
827 } | |
828 else | |
829 { | |
830 return defaultValue; | |
831 } | |
3026 | 832 } |
833 | |
3028 | 834 |
835 float OrthancConfiguration::GetFloatValue(const std::string& key, | |
836 float defaultValue) const | |
3026 | 837 { |
3028 | 838 float tmp; |
839 if (LookupFloatValue(tmp, key)) | |
840 { | |
841 return tmp; | |
842 } | |
843 else | |
844 { | |
845 return defaultValue; | |
846 } | |
3026 | 847 } |
848 | |
849 | |
3028 | 850 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target, |
851 const std::string& key) const | |
3026 | 852 { |
3028 | 853 assert(configuration_.type() == Json::objectValue); |
854 | |
855 target.clear(); | |
856 | |
857 if (!configuration_.isMember(key)) | |
858 { | |
859 return; | |
860 } | |
3026 | 861 |
3028 | 862 if (configuration_[key].type() != Json::objectValue) |
863 { | |
864 LogError("The configuration option \"" + GetPath(key) + | |
865 "\" is not a string as expected"); | |
866 | |
867 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
868 } | |
3026 | 869 |
3028 | 870 Json::Value::Members members = configuration_[key].getMemberNames(); |
871 | |
872 for (size_t i = 0; i < members.size(); i++) | |
3026 | 873 { |
3028 | 874 const Json::Value& value = configuration_[key][members[i]]; |
875 | |
876 if (value.type() == Json::stringValue) | |
3026 | 877 { |
3028 | 878 target[members[i]] = value.asString(); |
3026 | 879 } |
880 else | |
881 { | |
3028 | 882 LogError("The configuration option \"" + GetPath(key) + |
883 "\" is not a dictionary mapping strings to strings"); | |
884 | |
885 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
3026 | 886 } |
887 } | |
3028 | 888 } |
3026 | 889 |
3028 | 890 |
891 void OrthancImage::Clear() | |
892 { | |
893 if (image_ != NULL) | |
894 { | |
895 OrthancPluginFreeImage(GetGlobalContext(), image_); | |
896 image_ = NULL; | |
897 } | |
898 } | |
899 | |
900 | |
3236 | 901 void OrthancImage::CheckImageAvailable() const |
3028 | 902 { |
903 if (image_ == NULL) | |
904 { | |
905 LogError("Trying to access a NULL image"); | |
906 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
907 } | |
908 } | |
909 | |
910 | |
911 OrthancImage::OrthancImage() : | |
912 image_(NULL) | |
913 { | |
914 } | |
915 | |
916 | |
917 OrthancImage::OrthancImage(OrthancPluginImage* image) : | |
918 image_(image) | |
919 { | |
920 } | |
921 | |
922 | |
923 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
924 uint32_t width, | |
925 uint32_t height) | |
926 { | |
927 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); | |
928 | |
929 if (image_ == NULL) | |
930 { | |
931 LogError("Cannot create an image"); | |
932 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
933 } | |
934 } | |
935 | |
936 | |
937 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
938 uint32_t width, | |
939 uint32_t height, | |
940 uint32_t pitch, | |
941 void* buffer) | |
942 { | |
943 image_ = OrthancPluginCreateImageAccessor | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
944 (GetGlobalContext(), format, width, height, pitch, buffer); |
3028 | 945 |
946 if (image_ == NULL) | |
947 { | |
948 LogError("Cannot create an image accessor"); | |
949 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
950 } | |
951 } | |
952 | |
953 void OrthancImage::UncompressPngImage(const void* data, | |
954 size_t size) | |
955 { | |
956 Clear(); | |
957 | |
958 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); | |
959 | |
960 if (image_ == NULL) | |
961 { | |
962 LogError("Cannot uncompress a PNG image"); | |
963 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
964 } | |
965 } | |
966 | |
967 | |
968 void OrthancImage::UncompressJpegImage(const void* data, | |
969 size_t size) | |
970 { | |
971 Clear(); | |
972 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); | |
973 if (image_ == NULL) | |
974 { | |
975 LogError("Cannot uncompress a JPEG image"); | |
976 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
977 } | |
978 } | |
979 | |
980 | |
981 void OrthancImage::DecodeDicomImage(const void* data, | |
982 size_t size, | |
983 unsigned int frame) | |
984 { | |
985 Clear(); | |
986 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); | |
987 if (image_ == NULL) | |
988 { | |
989 LogError("Cannot uncompress a DICOM image"); | |
990 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
991 } | |
992 } | |
993 | |
994 | |
3236 | 995 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const |
3028 | 996 { |
997 CheckImageAvailable(); | |
998 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); | |
999 } | |
1000 | |
1001 | |
3236 | 1002 unsigned int OrthancImage::GetWidth() const |
3028 | 1003 { |
1004 CheckImageAvailable(); | |
1005 return OrthancPluginGetImageWidth(GetGlobalContext(), image_); | |
1006 } | |
1007 | |
1008 | |
3236 | 1009 unsigned int OrthancImage::GetHeight() const |
3028 | 1010 { |
1011 CheckImageAvailable(); | |
1012 return OrthancPluginGetImageHeight(GetGlobalContext(), image_); | |
1013 } | |
1014 | |
1015 | |
3236 | 1016 unsigned int OrthancImage::GetPitch() const |
3028 | 1017 { |
1018 CheckImageAvailable(); | |
1019 return OrthancPluginGetImagePitch(GetGlobalContext(), image_); | |
1020 } | |
1021 | |
1022 | |
3236 | 1023 const void* OrthancImage::GetBuffer() const |
3028 | 1024 { |
1025 CheckImageAvailable(); | |
1026 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); | |
1027 } | |
1028 | |
1029 | |
3236 | 1030 void OrthancImage::CompressPngImage(MemoryBuffer& target) const |
3028 | 1031 { |
1032 CheckImageAvailable(); | |
1033 | |
3320 | 1034 OrthancPlugins::MemoryBuffer answer; |
1035 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1036 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); |
1037 | |
3320 | 1038 target.Swap(answer); |
3028 | 1039 } |
1040 | |
1041 | |
1042 void OrthancImage::CompressJpegImage(MemoryBuffer& target, | |
3236 | 1043 uint8_t quality) const |
3028 | 1044 { |
1045 CheckImageAvailable(); | |
1046 | |
3320 | 1047 OrthancPlugins::MemoryBuffer answer; |
1048 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
3028 | 1049 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); |
1050 | |
3320 | 1051 target.Swap(answer); |
3028 | 1052 } |
1053 | |
1054 | |
3236 | 1055 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const |
3028 | 1056 { |
1057 CheckImageAvailable(); | |
1058 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), | |
1059 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | |
1060 } | |
1061 | |
1062 | |
1063 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, | |
3236 | 1064 uint8_t quality) const |
3028 | 1065 { |
1066 CheckImageAvailable(); | |
1067 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), | |
1068 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | |
1069 } | |
1070 | |
1071 | |
1072 | |
1073 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 | |
1074 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : | |
1075 matcher_(NULL), | |
1076 worklist_(worklist) | |
1077 { | |
1078 if (worklist_ == NULL) | |
1079 { | |
1080 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1081 } | |
1082 } | |
1083 | |
1084 | |
1085 void FindMatcher::SetupDicom(const void* query, | |
1086 uint32_t size) | |
1087 { | |
1088 worklist_ = NULL; | |
1089 | |
1090 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); | |
1091 if (matcher_ == NULL) | |
1092 { | |
1093 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1094 } | |
1095 } | |
1096 | |
1097 | |
1098 FindMatcher::~FindMatcher() | |
1099 { | |
1100 // The "worklist_" field | |
1101 | |
1102 if (matcher_ != NULL) | |
1103 { | |
1104 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); | |
1105 } | |
1106 } | |
1107 | |
1108 | |
1109 | |
1110 bool FindMatcher::IsMatch(const void* dicom, | |
1111 uint32_t size) const | |
1112 { | |
1113 int32_t result; | |
1114 | |
1115 if (matcher_ != NULL) | |
1116 { | |
1117 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); | |
1118 } | |
1119 else if (worklist_ != NULL) | |
1120 { | |
1121 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); | |
1122 } | |
1123 else | |
1124 { | |
1125 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1126 } | |
1127 | |
1128 if (result == 0) | |
1129 { | |
1130 return false; | |
1131 } | |
1132 else if (result == 1) | |
1133 { | |
1134 return true; | |
1135 } | |
1136 else | |
1137 { | |
1138 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1139 } | |
1140 } | |
1141 | |
1142 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | |
1143 | |
1144 void AnswerJson(const Json::Value& value, | |
1145 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1146 ) |
3028 | 1147 { |
1148 Json::StyledWriter writer; | |
1149 std::string bodyString = writer.write(value); | |
1150 | |
1151 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); | |
1152 } | |
1153 | |
1154 void AnswerString(const std::string& answer, | |
1155 const char* mimeType, | |
1156 OrthancPluginRestOutput* output | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1157 ) |
3028 | 1158 { |
1159 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); | |
1160 } | |
1161 | |
1162 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) | |
1163 { | |
1164 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); | |
1165 } | |
1166 | |
1167 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) | |
1168 { | |
1169 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); | |
1170 } | |
1171 | |
1172 bool RestApiGetString(std::string& result, | |
1173 const std::string& uri, | |
1174 bool applyPlugins) | |
1175 { | |
1176 MemoryBuffer answer; | |
1177 if (!answer.RestApiGet(uri, applyPlugins)) | |
1178 { | |
1179 return false; | |
1180 } | |
1181 else | |
1182 { | |
1183 answer.ToString(result); | |
1184 return true; | |
1185 } | |
1186 } | |
1187 | |
1188 bool RestApiGetString(std::string& result, | |
1189 const std::string& uri, | |
1190 const std::map<std::string, std::string>& httpHeaders, | |
1191 bool applyPlugins) | |
1192 { | |
1193 MemoryBuffer answer; | |
1194 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) | |
1195 { | |
1196 return false; | |
1197 } | |
1198 else | |
1199 { | |
1200 answer.ToString(result); | |
1201 return true; | |
1202 } | |
1203 } | |
1204 | |
1205 | |
1206 | |
1207 bool RestApiGet(Json::Value& result, | |
1208 const std::string& uri, | |
1209 bool applyPlugins) | |
1210 { | |
1211 MemoryBuffer answer; | |
1212 | |
1213 if (!answer.RestApiGet(uri, applyPlugins)) | |
1214 { | |
1215 return false; | |
1216 } | |
1217 else | |
1218 { | |
1219 if (!answer.IsEmpty()) | |
1220 { | |
1221 answer.ToJson(result); | |
1222 } | |
1223 return true; | |
1224 } | |
1225 } | |
1226 | |
1227 | |
1228 bool RestApiPost(Json::Value& result, | |
1229 const std::string& uri, | |
1230 const char* body, | |
1231 size_t bodySize, | |
1232 bool applyPlugins) | |
1233 { | |
1234 MemoryBuffer answer; | |
1235 | |
1236 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) | |
1237 { | |
1238 return false; | |
1239 } | |
1240 else | |
1241 { | |
1242 if (!answer.IsEmpty()) | |
1243 { | |
1244 answer.ToJson(result); | |
1245 } | |
1246 return true; | |
1247 } | |
1248 } | |
1249 | |
1250 | |
1251 bool RestApiPost(Json::Value& result, | |
1252 const std::string& uri, | |
1253 const Json::Value& body, | |
1254 bool applyPlugins) | |
1255 { | |
1256 Json::FastWriter writer; | |
1257 return RestApiPost(result, uri, writer.write(body), applyPlugins); | |
1258 } | |
1259 | |
1260 | |
1261 bool RestApiPut(Json::Value& result, | |
1262 const std::string& uri, | |
1263 const char* body, | |
1264 size_t bodySize, | |
1265 bool applyPlugins) | |
1266 { | |
1267 MemoryBuffer answer; | |
1268 | |
1269 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) | |
1270 { | |
1271 return false; | |
1272 } | |
1273 else | |
1274 { | |
1275 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthand returns an empty response | |
1276 { | |
1277 answer.ToJson(result); | |
1278 } | |
1279 return true; | |
1280 } | |
1281 } | |
1282 | |
1283 | |
1284 bool RestApiPut(Json::Value& result, | |
1285 const std::string& uri, | |
1286 const Json::Value& body, | |
1287 bool applyPlugins) | |
1288 { | |
1289 Json::FastWriter writer; | |
1290 return RestApiPut(result, uri, writer.write(body), applyPlugins); | |
1291 } | |
1292 | |
1293 | |
1294 bool RestApiDelete(const std::string& uri, | |
1295 bool applyPlugins) | |
1296 { | |
1297 OrthancPluginErrorCode error; | |
1298 | |
1299 if (applyPlugins) | |
1300 { | |
1301 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); | |
1302 } | |
1303 else | |
1304 { | |
1305 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); | |
1306 } | |
1307 | |
1308 if (error == OrthancPluginErrorCode_Success) | |
1309 { | |
1310 return true; | |
1311 } | |
1312 else if (error == OrthancPluginErrorCode_UnknownResource || | |
1313 error == OrthancPluginErrorCode_InexistentItem) | |
1314 { | |
1315 return false; | |
1316 } | |
1317 else | |
1318 { | |
1319 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
1320 } | |
1321 } | |
1322 | |
1323 | |
1324 void ReportMinimalOrthancVersion(unsigned int major, | |
1325 unsigned int minor, | |
1326 unsigned int revision) | |
1327 { | |
1328 LogError("Your version of the Orthanc core (" + | |
1329 std::string(GetGlobalContext()->orthancVersion) + | |
1330 ") is too old to run this plugin (version " + | |
1331 boost::lexical_cast<std::string>(major) + "." + | |
1332 boost::lexical_cast<std::string>(minor) + "." + | |
1333 boost::lexical_cast<std::string>(revision) + | |
1334 " is required)"); | |
1335 } | |
1336 | |
1337 | |
1338 bool CheckMinimalOrthancVersion(unsigned int major, | |
1339 unsigned int minor, | |
1340 unsigned int revision) | |
1341 { | |
1342 if (!HasGlobalContext()) | |
1343 { | |
1344 LogError("Bad Orthanc context in the plugin"); | |
1345 return false; | |
1346 } | |
1347 | |
1348 if (!strcmp(GetGlobalContext()->orthancVersion, "mainline")) | |
1349 { | |
1350 // Assume compatibility with the mainline | |
1351 return true; | |
1352 } | |
1353 | |
1354 // Parse the version of the Orthanc core | |
1355 int aa, bb, cc; | |
1356 if ( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1357 #ifdef _MSC_VER |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1358 sscanf_s |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1359 #else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1360 sscanf |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1361 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1362 (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
|
1363 aa < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1364 bb < 0 || |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1365 cc < 0) |
3028 | 1366 { |
1367 return false; | |
1368 } | |
1369 | |
1370 unsigned int a = static_cast<unsigned int>(aa); | |
1371 unsigned int b = static_cast<unsigned int>(bb); | |
1372 unsigned int c = static_cast<unsigned int>(cc); | |
1373 | |
1374 // Check the major version number | |
1375 | |
1376 if (a > major) | |
3026 | 1377 { |
1378 return true; | |
1379 } | |
1380 | |
3028 | 1381 if (a < major) |
1382 { | |
1383 return false; | |
1384 } | |
1385 | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1386 |
3028 | 1387 // Check the minor version number |
1388 assert(a == major); | |
1389 | |
1390 if (b > minor) | |
3026 | 1391 { |
1392 return true; | |
1393 } | |
2792
57e2d65d37ce
OrthancPlugins::MemoryBuffer::Release(), fixing openssl link
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1394 |
3028 | 1395 if (b < minor) |
3026 | 1396 { |
3028 | 1397 return false; |
3026 | 1398 } |
1399 | |
3028 | 1400 // Check the patch level version number |
1401 assert(a == major && b == minor); | |
3026 | 1402 |
3028 | 1403 if (c >= revision) |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1404 { |
3028 | 1405 return true; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1406 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1407 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1408 { |
3028 | 1409 return false; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1410 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1411 } |
2058
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1412 |
43cd2ab060c7
cont OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2048
diff
changeset
|
1413 |
3028 | 1414 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) |
1415 const char* AutodetectMimeType(const std::string& path) | |
3026 | 1416 { |
3028 | 1417 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
|
1418 |
3028 | 1419 if (mime == NULL) |
1420 { | |
1421 // Should never happen, just for safety | |
1422 return "application/octet-stream"; | |
1423 } | |
1424 else | |
1425 { | |
1426 return mime; | |
1427 } | |
2848 | 1428 } |
3026 | 1429 #endif |
1430 | |
1431 | |
1432 #if HAS_ORTHANC_PLUGIN_PEERS == 1 | |
3028 | 1433 size_t OrthancPeers::GetPeerIndex(const std::string& name) const |
3026 | 1434 { |
3028 | 1435 size_t index; |
1436 if (LookupName(index, name)) | |
1437 { | |
1438 return index; | |
1439 } | |
1440 else | |
1441 { | |
1442 LogError("Inexistent peer: " + name); | |
1443 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); | |
1444 } | |
3026 | 1445 } |
2059 | 1446 |
1447 | |
3028 | 1448 OrthancPeers::OrthancPeers() : |
1449 peers_(NULL), | |
1450 timeout_(0) | |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1451 { |
3028 | 1452 peers_ = OrthancPluginGetPeers(GetGlobalContext()); |
3026 | 1453 |
3028 | 1454 if (peers_ == NULL) |
3026 | 1455 { |
1456 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1457 } | |
1458 | |
3028 | 1459 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); |
1460 | |
1461 for (uint32_t i = 0; i < count; i++) | |
1462 { | |
1463 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); | |
1464 if (name == NULL) | |
1465 { | |
1466 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1467 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1468 } | |
1469 | |
1470 index_[name] = i; | |
1471 } | |
1472 } | |
1473 | |
1474 | |
1475 OrthancPeers::~OrthancPeers() | |
1476 { | |
1477 if (peers_ != NULL) | |
1478 { | |
1479 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1480 } | |
1481 } | |
1482 | |
1483 | |
1484 bool OrthancPeers::LookupName(size_t& target, | |
1485 const std::string& name) const | |
1486 { | |
1487 Index::const_iterator found = index_.find(name); | |
1488 | |
1489 if (found == index_.end()) | |
1490 { | |
1491 return false; | |
1492 } | |
1493 else | |
1494 { | |
1495 target = found->second; | |
1496 return true; | |
1497 } | |
3026 | 1498 } |
3028 | 1499 |
1500 | |
1501 std::string OrthancPeers::GetPeerName(size_t index) const | |
1502 { | |
1503 if (index >= index_.size()) | |
1504 { | |
1505 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1506 } | |
1507 else | |
1508 { | |
1509 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1510 if (s == NULL) | |
1511 { | |
1512 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1513 } | |
1514 else | |
1515 { | |
1516 return s; | |
1517 } | |
1518 } | |
1519 } | |
1520 | |
1521 | |
1522 std::string OrthancPeers::GetPeerUrl(size_t index) const | |
1523 { | |
1524 if (index >= index_.size()) | |
1525 { | |
1526 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1527 } | |
1528 else | |
1529 { | |
1530 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1531 if (s == NULL) | |
1532 { | |
1533 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1534 } | |
1535 else | |
1536 { | |
1537 return s; | |
1538 } | |
1539 } | |
1540 } | |
1541 | |
1542 | |
1543 std::string OrthancPeers::GetPeerUrl(const std::string& name) const | |
1544 { | |
1545 return GetPeerUrl(GetPeerIndex(name)); | |
1546 } | |
1547 | |
1548 | |
1549 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1550 size_t index, | |
1551 const std::string& key) const | |
1552 { | |
1553 if (index >= index_.size()) | |
1554 { | |
1555 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1556 } | |
1557 else | |
1558 { | |
1559 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str()); | |
1560 if (s == NULL) | |
1561 { | |
1562 return false; | |
1563 } | |
1564 else | |
1565 { | |
1566 value.assign(s); | |
1567 return true; | |
1568 } | |
1569 } | |
1570 } | |
1571 | |
1572 | |
1573 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1574 const std::string& peer, | |
1575 const std::string& key) const | |
1576 { | |
1577 return LookupUserProperty(value, GetPeerIndex(peer), key); | |
1578 } | |
3026 | 1579 |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
1580 |
3028 | 1581 bool OrthancPeers::DoGet(MemoryBuffer& target, |
1582 size_t index, | |
1583 const std::string& uri) const | |
1584 { | |
1585 if (index >= index_.size()) | |
1586 { | |
1587 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1588 } | |
1589 | |
3320 | 1590 OrthancPlugins::MemoryBuffer answer; |
3028 | 1591 uint16_t status; |
1592 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1593 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1594 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
|
1595 0, NULL, NULL, NULL, 0, timeout_); |
3028 | 1596 |
1597 if (code == OrthancPluginErrorCode_Success) | |
1598 { | |
3320 | 1599 target.Swap(answer); |
3028 | 1600 return (status == 200); |
1601 } | |
1602 else | |
1603 { | |
1604 return false; | |
1605 } | |
1606 } | |
1607 | |
1608 | |
1609 bool OrthancPeers::DoGet(MemoryBuffer& target, | |
1610 const std::string& name, | |
1611 const std::string& uri) const | |
1612 { | |
1613 size_t index; | |
1614 return (LookupName(index, name) && | |
1615 DoGet(target, index, uri)); | |
1616 } | |
1617 | |
1618 | |
1619 bool OrthancPeers::DoGet(Json::Value& target, | |
1620 size_t index, | |
1621 const std::string& uri) const | |
1622 { | |
1623 MemoryBuffer buffer; | |
1624 | |
1625 if (DoGet(buffer, index, uri)) | |
1626 { | |
1627 buffer.ToJson(target); | |
1628 return true; | |
1629 } | |
1630 else | |
1631 { | |
1632 return false; | |
1633 } | |
1634 } | |
1635 | |
1636 | |
1637 bool OrthancPeers::DoGet(Json::Value& target, | |
1638 const std::string& name, | |
1639 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1640 { |
3028 | 1641 MemoryBuffer buffer; |
1642 | |
1643 if (DoGet(buffer, name, uri)) | |
1644 { | |
1645 buffer.ToJson(target); | |
1646 return true; | |
1647 } | |
1648 else | |
1649 { | |
1650 return false; | |
1651 } | |
1652 } | |
1653 | |
1654 | |
1655 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1656 const std::string& name, | |
1657 const std::string& uri, | |
1658 const std::string& body) const | |
1659 { | |
1660 size_t index; | |
1661 return (LookupName(index, name) && | |
1662 DoPost(target, index, uri, body)); | |
1663 } | |
1664 | |
1665 | |
1666 bool OrthancPeers::DoPost(Json::Value& target, | |
1667 size_t index, | |
1668 const std::string& uri, | |
1669 const std::string& body) const | |
1670 { | |
1671 MemoryBuffer buffer; | |
1672 | |
1673 if (DoPost(buffer, index, uri, body)) | |
1674 { | |
1675 buffer.ToJson(target); | |
1676 return true; | |
1677 } | |
1678 else | |
1679 { | |
1680 return false; | |
1681 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1682 } |
3028 | 1683 |
1684 | |
1685 bool OrthancPeers::DoPost(Json::Value& target, | |
1686 const std::string& name, | |
1687 const std::string& uri, | |
1688 const std::string& body) const | |
1689 { | |
1690 MemoryBuffer buffer; | |
1691 | |
1692 if (DoPost(buffer, name, uri, body)) | |
1693 { | |
1694 buffer.ToJson(target); | |
1695 return true; | |
1696 } | |
1697 else | |
1698 { | |
1699 return false; | |
1700 } | |
1701 } | |
1702 | |
1703 | |
1704 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1705 size_t index, | |
1706 const std::string& uri, | |
1707 const std::string& body) const | |
1708 { | |
1709 if (index >= index_.size()) | |
1710 { | |
1711 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1712 } | |
1713 | |
3320 | 1714 OrthancPlugins::MemoryBuffer answer; |
3028 | 1715 uint16_t status; |
1716 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1717 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1718 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
|
1719 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3028 | 1720 |
1721 if (code == OrthancPluginErrorCode_Success) | |
1722 { | |
3320 | 1723 target.Swap(answer); |
3028 | 1724 return (status == 200); |
1725 } | |
1726 else | |
1727 { | |
1728 return false; | |
1729 } | |
1730 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1731 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1732 |
3028 | 1733 bool OrthancPeers::DoPut(size_t index, |
1734 const std::string& uri, | |
1735 const std::string& body) const | |
1736 { | |
1737 if (index >= index_.size()) | |
1738 { | |
1739 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1740 } | |
1741 | |
3320 | 1742 OrthancPlugins::MemoryBuffer answer; |
3028 | 1743 uint16_t status; |
1744 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1745 (GetGlobalContext(), *answer, NULL, &status, peers_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
1746 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
|
1747 0, NULL, NULL, body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
3026 | 1748 |
3028 | 1749 if (code == OrthancPluginErrorCode_Success) |
1750 { | |
1751 return (status == 200); | |
1752 } | |
1753 else | |
1754 { | |
1755 return false; | |
1756 } | |
1757 } | |
1758 | |
1759 | |
1760 bool OrthancPeers::DoPut(const std::string& name, | |
1761 const std::string& uri, | |
1762 const std::string& body) const | |
1763 { | |
1764 size_t index; | |
1765 return (LookupName(index, name) && | |
1766 DoPut(index, uri, body)); | |
1767 } | |
1768 | |
1769 | |
1770 bool OrthancPeers::DoDelete(size_t index, | |
1771 const std::string& uri) const | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1772 { |
3028 | 1773 if (index >= index_.size()) |
1774 { | |
1775 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1776 } | |
1777 | |
3320 | 1778 OrthancPlugins::MemoryBuffer answer; |
3028 | 1779 uint16_t status; |
1780 OrthancPluginErrorCode code = OrthancPluginCallPeerApi | |
3320 | 1781 (GetGlobalContext(), *answer, NULL, &status, peers_, |
1782 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | |
1783 0, NULL, NULL, NULL, 0, timeout_); | |
3028 | 1784 |
1785 if (code == OrthancPluginErrorCode_Success) | |
1786 { | |
1787 return (status == 200); | |
1788 } | |
1789 else | |
1790 { | |
1791 return false; | |
1792 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1793 } |
3028 | 1794 |
1795 | |
1796 bool OrthancPeers::DoDelete(const std::string& name, | |
1797 const std::string& uri) const | |
3026 | 1798 { |
3028 | 1799 size_t index; |
1800 return (LookupName(index, name) && | |
1801 DoDelete(index, uri)); | |
1802 } | |
1803 #endif | |
1804 | |
1805 | |
1806 | |
1807 #if HAS_ORTHANC_PLUGIN_JOB == 1 | |
1808 void OrthancJob::CallbackFinalize(void* job) | |
1809 { | |
1810 if (job != NULL) | |
1811 { | |
1812 delete reinterpret_cast<OrthancJob*>(job); | |
1813 } | |
3026 | 1814 } |
3028 | 1815 |
1816 | |
1817 float OrthancJob::CallbackGetProgress(void* job) | |
1818 { | |
1819 assert(job != NULL); | |
1820 | |
1821 try | |
1822 { | |
1823 return reinterpret_cast<OrthancJob*>(job)->progress_; | |
1824 } | |
1825 catch (...) | |
1826 { | |
1827 return 0; | |
1828 } | |
1829 } | |
1830 | |
1831 | |
1832 const char* OrthancJob::CallbackGetContent(void* job) | |
1833 { | |
1834 assert(job != NULL); | |
1835 | |
1836 try | |
1837 { | |
1838 return reinterpret_cast<OrthancJob*>(job)->content_.c_str(); | |
1839 } | |
1840 catch (...) | |
1841 { | |
1842 return 0; | |
1843 } | |
1844 } | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1845 |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1846 |
3028 | 1847 const char* OrthancJob::CallbackGetSerialized(void* job) |
1848 { | |
1849 assert(job != NULL); | |
1850 | |
1851 try | |
1852 { | |
1853 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job); | |
1854 | |
1855 if (tmp.hasSerialized_) | |
1856 { | |
1857 return tmp.serialized_.c_str(); | |
1858 } | |
1859 else | |
1860 { | |
1861 return NULL; | |
1862 } | |
1863 } | |
1864 catch (...) | |
1865 { | |
1866 return 0; | |
1867 } | |
1868 } | |
1869 | |
1870 | |
1871 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | |
1872 { | |
1873 assert(job != NULL); | |
1874 | |
1875 try | |
1876 { | |
1877 return reinterpret_cast<OrthancJob*>(job)->Step(); | |
1878 } | |
1879 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) | |
1880 { | |
1881 return OrthancPluginJobStepStatus_Failure; | |
1882 } | |
1883 catch (...) | |
1884 { | |
1885 return OrthancPluginJobStepStatus_Failure; | |
1886 } | |
1887 } | |
1888 | |
1889 | |
1890 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, | |
1891 OrthancPluginJobStopReason reason) | |
1892 { | |
1893 assert(job != NULL); | |
1894 | |
1895 try | |
1896 { | |
1897 reinterpret_cast<OrthancJob*>(job)->Stop(reason); | |
1898 return OrthancPluginErrorCode_Success; | |
1899 } | |
1900 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1901 { | |
1902 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1903 } | |
1904 catch (...) | |
1905 { | |
1906 return OrthancPluginErrorCode_Plugin; | |
1907 } | |
1908 } | |
1909 | |
1910 | |
1911 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1912 { |
3028 | 1913 assert(job != NULL); |
1914 | |
1915 try | |
1916 { | |
1917 reinterpret_cast<OrthancJob*>(job)->Reset(); | |
1918 return OrthancPluginErrorCode_Success; | |
1919 } | |
1920 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
1921 { | |
1922 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
1923 } | |
1924 catch (...) | |
1925 { | |
1926 return OrthancPluginErrorCode_Plugin; | |
1927 } | |
1928 } | |
1929 | |
1930 | |
1931 void OrthancJob::ClearContent() | |
1932 { | |
1933 Json::Value empty = Json::objectValue; | |
1934 UpdateContent(empty); | |
1935 } | |
1936 | |
1937 | |
1938 void OrthancJob::UpdateContent(const Json::Value& content) | |
1939 { | |
1940 if (content.type() != Json::objectValue) | |
1941 { | |
1942 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
1943 } | |
1944 else | |
1945 { | |
1946 Json::FastWriter writer; | |
1947 content_ = writer.write(content); | |
1948 } | |
1949 } | |
1950 | |
1951 | |
1952 void OrthancJob::ClearSerialized() | |
1953 { | |
1954 hasSerialized_ = false; | |
1955 serialized_.clear(); | |
3026 | 1956 } |
3028 | 1957 |
1958 | |
1959 void OrthancJob::UpdateSerialized(const Json::Value& serialized) | |
1960 { | |
1961 if (serialized.type() != Json::objectValue) | |
1962 { | |
1963 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
1964 } | |
1965 else | |
1966 { | |
1967 Json::FastWriter writer; | |
1968 serialized_ = writer.write(serialized); | |
1969 hasSerialized_ = true; | |
1970 } | |
1971 } | |
1972 | |
1973 | |
1974 void OrthancJob::UpdateProgress(float progress) | |
3026 | 1975 { |
3028 | 1976 if (progress < 0 || |
1977 progress > 1) | |
1978 { | |
1979 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1980 } | |
1981 | |
1982 progress_ = progress; | |
1983 } | |
1984 | |
1985 | |
1986 OrthancJob::OrthancJob(const std::string& jobType) : | |
1987 jobType_(jobType), | |
1988 progress_(0) | |
1989 { | |
1990 ClearContent(); | |
1991 ClearSerialized(); | |
1992 } | |
1993 | |
1994 | |
1995 OrthancPluginJob* OrthancJob::Create(OrthancJob* job) | |
1996 { | |
1997 if (job == NULL) | |
1998 { | |
1999 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | |
2000 } | |
2001 | |
2002 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2003 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
|
2004 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2005 CallbackStep, CallbackStop, CallbackReset); |
3028 | 2006 |
2007 if (orthanc == NULL) | |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2008 { |
3026 | 2009 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2010 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2011 else |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2012 { |
3028 | 2013 return orthanc; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2014 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2015 } |
2205
395522e46b2b
refactoring of the worklist sample using OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2177
diff
changeset
|
2016 |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2017 |
3028 | 2018 std::string OrthancJob::Submit(OrthancJob* job, |
2019 int priority) | |
2264
8e5e0de75839
primitives for HTTP client in plugin C++ wrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2263
diff
changeset
|
2020 { |
3028 | 2021 OrthancPluginJob* orthanc = Create(job); |
2022 | |
2023 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); | |
2024 | |
2025 if (id == NULL) | |
3026 | 2026 { |
3028 | 2027 LogError("Plugin cannot submit job"); |
2028 OrthancPluginFreeJob(GetGlobalContext(), orthanc); | |
3026 | 2029 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); |
2030 } | |
2031 else | |
2032 { | |
3028 | 2033 std::string tmp(id); |
2034 tmp.assign(id); | |
2035 OrthancPluginFreeString(GetGlobalContext(), id); | |
3026 | 2036 |
3028 | 2037 return tmp; |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2038 } |
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2039 } |
2817
473bf302d629
C++ wrappers around OrthancPluginJob and OrthancPluginPeers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2803
diff
changeset
|
2040 #endif |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2041 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2042 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2043 #if HAS_ORTHANC_PLUGIN_METRICS == 1 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2044 MetricsTimer::MetricsTimer(const char* name) : |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2045 name_(name) |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2046 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2047 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
|
2048 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2049 |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2050 MetricsTimer::~MetricsTimer() |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2051 { |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2052 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
|
2053 const boost::posix_time::time_duration diff = stop - start_; |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2054 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), diff.total_milliseconds(), |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2055 OrthancPluginMetricsType_Timer); |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2056 } |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
2057 #endif |
3387
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2058 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2059 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2060 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2061 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2062 class HttpClient::ChunkedBody : public boost::noncopyable |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2063 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2064 private: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2065 static ChunkedBody& GetObject(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2066 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2067 assert(body != NULL); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2068 return *reinterpret_cast<ChunkedBody*>(body); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2069 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2070 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2071 IChunkedBody& body_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2072 bool done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2073 std::string chunk_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2074 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2075 public: |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2076 ChunkedBody(IChunkedBody& body) : |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2077 body_(body), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2078 done_(false) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2079 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2080 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2081 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2082 static uint8_t IsDone(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2083 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2084 return GetObject(body).done_; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2085 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2086 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2087 static const void* GetChunkData(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2088 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2089 return GetObject(body).chunk_.c_str(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2090 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2091 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2092 static uint32_t GetChunkSize(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2093 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2094 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
|
2095 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2096 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2097 static OrthancPluginErrorCode Next(void* body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2098 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2099 ChunkedBody& that = GetObject(body); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2100 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2101 if (that.done_) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2102 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2103 return OrthancPluginErrorCode_BadSequenceOfCalls; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2104 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2105 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2106 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2107 try |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2108 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2109 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
|
2110 return OrthancPluginErrorCode_Success; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2111 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2112 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2113 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2114 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2115 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2116 catch (...) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2117 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2118 return OrthancPluginErrorCode_InternalError; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2119 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2120 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2121 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2122 }; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2123 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2124 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2125 HttpClient::HttpClient() : |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2126 httpStatus_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2127 method_(OrthancPluginHttpMethod_Get), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2128 timeout_(0), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2129 pkcs11_(false), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2130 chunkedBody_(NULL) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2131 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2132 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2133 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2134 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2135 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
|
2136 const std::string& password) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2137 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2138 username_ = username; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2139 password_ = password; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2140 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2141 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2142 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2143 void HttpClient::ClearCredentials() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2144 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2145 username_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2146 password_.empty(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2147 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2148 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2149 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2150 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
|
2151 const std::string& keyFile, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2152 const std::string& keyPassword) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2153 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2154 certificateFile_ = certificateFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2155 certificateKeyFile_ = keyFile; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2156 certificateKeyPassword_ = keyPassword; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2157 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2158 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2159 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2160 void HttpClient::ClearCertificate() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2161 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2162 certificateFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2163 certificateKeyFile_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2164 certificateKeyPassword_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2165 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2166 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2167 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2168 void HttpClient::ClearBody() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2169 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2170 body_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2171 chunkedBody_ = NULL; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2172 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2173 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2174 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2175 void HttpClient::SwapBody(std::string& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2176 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2177 body_.swap(body); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2178 chunkedBody_ = NULL; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2179 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2180 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2181 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2182 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
|
2183 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2184 body_ = body; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2185 chunkedBody_ = NULL; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2186 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2187 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2188 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2189 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY == 1 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2190 void HttpClient::SetBody(IChunkedBody& body) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2191 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2192 body_.clear(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2193 chunkedBody_ = &body; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2194 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2195 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2196 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2197 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2198 void HttpClient::Execute() |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2199 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2200 std::vector<const char*> headersKeys; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2201 std::vector<const char*> headersValues; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2202 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2203 headersKeys.reserve(headers_.size()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2204 headersValues.reserve(headers_.size()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2205 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2206 for (HttpHeaders::const_iterator it = headers_.begin(); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2207 it != headers_.end(); ++it) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2208 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2209 headersKeys.push_back(it->first.c_str()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2210 headersValues.push_back(it->second.c_str()); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2211 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2212 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2213 OrthancPluginErrorCode error; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2214 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2215 if (chunkedBody_ == NULL) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2216 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2217 error = OrthancPluginHttpClient( |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2218 GetGlobalContext(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2219 *answerBody_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2220 *answerHeaders_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2221 &httpStatus_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2222 method_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2223 url_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2224 headersKeys.size(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2225 headersKeys.empty() ? NULL : &headersKeys[0], |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2226 headersValues.empty() ? NULL : &headersValues[0], |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2227 body_.empty() ? NULL : body_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2228 body_.size(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2229 username_.empty() ? NULL : username_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2230 password_.empty() ? NULL : password_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2231 timeout_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2232 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2233 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2234 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2235 pkcs11_ ? 1 : 0); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2236 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2237 else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2238 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2239 #if HAS_ORTHANC_PLUGIN_HTTP_CHUNKED_BODY != 1 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2240 error = OrthancPluginErrorCode_InternalError; |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2241 #else |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2242 ChunkedBody wrapper(*chunkedBody_); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2243 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2244 error = OrthancPluginHttpClientChunkedBody( |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2245 GetGlobalContext(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2246 *answerBody_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2247 *answerHeaders_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2248 &httpStatus_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2249 method_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2250 url_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2251 headersKeys.size(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2252 headersKeys.empty() ? NULL : &headersKeys[0], |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2253 headersValues.empty() ? NULL : &headersValues[0], |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2254 username_.empty() ? NULL : username_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2255 password_.empty() ? NULL : password_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2256 timeout_, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2257 certificateFile_.empty() ? NULL : certificateFile_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2258 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2259 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2260 pkcs11_ ? 1 : 0, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2261 &wrapper, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2262 ChunkedBody::IsDone, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2263 ChunkedBody::GetChunkData, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2264 ChunkedBody::GetChunkSize, |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2265 ChunkedBody::Next); |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2266 #endif |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2267 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2268 |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2269 if (error != OrthancPluginErrorCode_Success) |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2270 { |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2271 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
|
2272 } |
a48d652f1500
new function OrthancPluginHttpClientChunkedBody(), new class OrthancPlugins::HttpClient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3320
diff
changeset
|
2273 } |
2047
438f86ee19fc
toolbox shared by all plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2274 } |