Mercurial > hg > orthanc-transfers
annotate Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 48:5493447a0d28
missing integration OrthancTransfers-1.3->mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 05 Dec 2022 14:24:27 +0100 |
parents | f4e828607f02 |
children | 5915547fa6f2 |
rev | line source |
---|---|
22 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
22 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
28 | 12 * |
22 | 13 * This program is distributed in the hope that it will be useful, but |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "OrthancPluginCppWrapper.h" | |
24 | |
25 #include <boost/algorithm/string/predicate.hpp> | |
26 #include <boost/move/unique_ptr.hpp> | |
27 #include <boost/thread.hpp> | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
28 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
29 |
22 | 30 #include <json/reader.h> |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
31 #include <json/version.h> |
22 | 32 #include <json/writer.h> |
33 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
34 #if !defined(JSONCPP_VERSION_MAJOR) || !defined(JSONCPP_VERSION_MINOR) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
35 # error Cannot access the version of JsonCpp |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
36 #endif |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
37 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
38 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
39 /** |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
40 * We use deprecated "Json::Reader", "Json::StyledWriter" and |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
41 * "Json::FastWriter" if JsonCpp < 1.7.0. This choice is rather |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
42 * arbitrary, but if Json >= 1.9.0, gcc generates explicit deprecation |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
43 * warnings (clang was warning in earlier versions). For reference, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
44 * these classes seem to have been deprecated since JsonCpp 1.4.0 (on |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
45 * February 2015) by the following changeset: |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
46 * https://github.com/open-source-parsers/jsoncpp/commit/8df98f6112890d6272734975dd6d70cf8999bb22 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
47 **/ |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
48 #if (JSONCPP_VERSION_MAJOR >= 2 || \ |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
49 (JSONCPP_VERSION_MAJOR == 1 && JSONCPP_VERSION_MINOR >= 8)) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
50 # define JSONCPP_USE_DEPRECATED 0 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
51 #else |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
52 # define JSONCPP_USE_DEPRECATED 1 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
53 #endif |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
54 |
22 | 55 |
56 #if !ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 0) | |
57 static const OrthancPluginErrorCode OrthancPluginErrorCode_NullPointer = OrthancPluginErrorCode_Plugin; | |
58 #endif | |
59 | |
60 | |
61 namespace OrthancPlugins | |
62 { | |
63 static OrthancPluginContext* globalContext_ = NULL; | |
64 | |
65 | |
66 void SetGlobalContext(OrthancPluginContext* context) | |
67 { | |
68 if (context == NULL) | |
69 { | |
70 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
71 } | |
72 else if (globalContext_ == NULL) | |
73 { | |
74 globalContext_ = context; | |
75 } | |
76 else | |
77 { | |
78 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
79 } | |
80 } | |
81 | |
82 | |
83 bool HasGlobalContext() | |
84 { | |
85 return globalContext_ != NULL; | |
86 } | |
87 | |
88 | |
89 OrthancPluginContext* GetGlobalContext() | |
90 { | |
91 if (globalContext_ == NULL) | |
92 { | |
93 ORTHANC_PLUGINS_THROW_EXCEPTION(BadSequenceOfCalls); | |
94 } | |
95 else | |
96 { | |
97 return globalContext_; | |
98 } | |
99 } | |
100 | |
101 | |
102 void MemoryBuffer::Check(OrthancPluginErrorCode code) | |
103 { | |
104 if (code != OrthancPluginErrorCode_Success) | |
105 { | |
106 // Prevent using garbage information | |
107 buffer_.data = NULL; | |
108 buffer_.size = 0; | |
109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
110 } | |
111 } | |
112 | |
113 | |
114 bool MemoryBuffer::CheckHttp(OrthancPluginErrorCode code) | |
115 { | |
116 if (code != OrthancPluginErrorCode_Success) | |
117 { | |
118 // Prevent using garbage information | |
119 buffer_.data = NULL; | |
120 buffer_.size = 0; | |
121 } | |
122 | |
123 if (code == OrthancPluginErrorCode_Success) | |
124 { | |
125 return true; | |
126 } | |
127 else if (code == OrthancPluginErrorCode_UnknownResource || | |
128 code == OrthancPluginErrorCode_InexistentItem) | |
129 { | |
130 return false; | |
131 } | |
132 else | |
133 { | |
134 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
135 } | |
136 } | |
137 | |
138 | |
139 MemoryBuffer::MemoryBuffer() | |
140 { | |
141 buffer_.data = NULL; | |
142 buffer_.size = 0; | |
143 } | |
144 | |
145 | |
146 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
147 MemoryBuffer::MemoryBuffer(const void* buffer, | |
148 size_t size) | |
149 { | |
150 uint32_t s = static_cast<uint32_t>(size); | |
151 if (static_cast<size_t>(s) != size) | |
152 { | |
153 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); | |
154 } | |
155 else if (OrthancPluginCreateMemoryBuffer(GetGlobalContext(), &buffer_, s) != | |
156 OrthancPluginErrorCode_Success) | |
157 { | |
158 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); | |
159 } | |
160 else | |
161 { | |
162 memcpy(buffer_.data, buffer, size); | |
163 } | |
164 } | |
165 #endif | |
166 | |
167 | |
168 void MemoryBuffer::Clear() | |
169 { | |
170 if (buffer_.data != NULL) | |
171 { | |
172 OrthancPluginFreeMemoryBuffer(GetGlobalContext(), &buffer_); | |
173 buffer_.data = NULL; | |
174 buffer_.size = 0; | |
175 } | |
176 } | |
177 | |
178 | |
179 void MemoryBuffer::Assign(OrthancPluginMemoryBuffer& other) | |
180 { | |
181 Clear(); | |
182 | |
183 buffer_.data = other.data; | |
184 buffer_.size = other.size; | |
185 | |
186 other.data = NULL; | |
187 other.size = 0; | |
188 } | |
189 | |
190 | |
191 void MemoryBuffer::Swap(MemoryBuffer& other) | |
192 { | |
193 std::swap(buffer_.data, other.buffer_.data); | |
194 std::swap(buffer_.size, other.buffer_.size); | |
195 } | |
196 | |
197 | |
198 OrthancPluginMemoryBuffer MemoryBuffer::Release() | |
199 { | |
200 OrthancPluginMemoryBuffer result = buffer_; | |
201 | |
202 buffer_.data = NULL; | |
203 buffer_.size = 0; | |
204 | |
205 return result; | |
206 } | |
207 | |
208 | |
209 void MemoryBuffer::ToString(std::string& target) const | |
210 { | |
211 if (buffer_.size == 0) | |
212 { | |
213 target.clear(); | |
214 } | |
215 else | |
216 { | |
217 target.assign(reinterpret_cast<const char*>(buffer_.data), buffer_.size); | |
218 } | |
219 } | |
220 | |
221 | |
222 void MemoryBuffer::ToJson(Json::Value& target) const | |
223 { | |
224 if (buffer_.data == NULL || | |
225 buffer_.size == 0) | |
226 { | |
227 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
228 } | |
229 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
230 if (!ReadJson(target, buffer_.data, buffer_.size)) |
22 | 231 { |
232 LogError("Cannot convert some memory buffer to JSON"); | |
233 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
234 } | |
235 } | |
236 | |
237 | |
238 bool MemoryBuffer::RestApiGet(const std::string& uri, | |
239 bool applyPlugins) | |
240 { | |
241 Clear(); | |
242 | |
243 if (applyPlugins) | |
244 { | |
245 return CheckHttp(OrthancPluginRestApiGetAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str())); | |
246 } | |
247 else | |
248 { | |
249 return CheckHttp(OrthancPluginRestApiGet(GetGlobalContext(), &buffer_, uri.c_str())); | |
250 } | |
251 } | |
252 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
253 // helper class to convert std::map of headers to the plugin SDK C structure |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
254 class PluginHttpHeaders |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
255 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
256 std::vector<const char*> headersKeys_; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
257 std::vector<const char*> headersValues_; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
258 public: |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
259 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
260 PluginHttpHeaders(const std::map<std::string, std::string>& httpHeaders) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
261 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
262 for (std::map<std::string, std::string>::const_iterator |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
263 it = httpHeaders.begin(); it != httpHeaders.end(); it++) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
264 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
265 headersKeys_.push_back(it->first.c_str()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
266 headersValues_.push_back(it->second.c_str()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
267 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
268 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
269 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
270 const char* const* GetKeys() |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
271 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
272 return (headersKeys_.empty() ? NULL : &headersKeys_[0]); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
273 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
274 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
275 const char* const* GetValues() |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
276 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
277 return (headersValues_.empty() ? NULL : &headersValues_[0]); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
278 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
279 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
280 uint32_t GetSize() |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
281 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
282 return static_cast<uint32_t>(headersKeys_.size()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
283 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
284 }; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
285 |
22 | 286 bool MemoryBuffer::RestApiGet(const std::string& uri, |
287 const std::map<std::string, std::string>& httpHeaders, | |
288 bool applyPlugins) | |
289 { | |
290 Clear(); | |
291 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
292 PluginHttpHeaders headers(httpHeaders); |
22 | 293 |
294 return CheckHttp(OrthancPluginRestApiGet2( | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
295 GetGlobalContext(), &buffer_, uri.c_str(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
296 headers.GetSize(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
297 headers.GetKeys(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
298 headers.GetValues(), applyPlugins)); |
22 | 299 } |
300 | |
301 bool MemoryBuffer::RestApiPost(const std::string& uri, | |
302 const void* body, | |
303 size_t bodySize, | |
304 bool applyPlugins) | |
305 { | |
306 Clear(); | |
307 | |
308 // Cast for compatibility with Orthanc SDK <= 1.5.6 | |
309 const char* b = reinterpret_cast<const char*>(body); | |
310 | |
311 if (applyPlugins) | |
312 { | |
313 return CheckHttp(OrthancPluginRestApiPostAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); | |
314 } | |
315 else | |
316 { | |
317 return CheckHttp(OrthancPluginRestApiPost(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); | |
318 } | |
319 } | |
320 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
321 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
322 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
323 bool MemoryBuffer::RestApiPost(const std::string& uri, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
324 const void* body, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
325 size_t bodySize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
326 const std::map<std::string, std::string>& httpHeaders, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
327 bool applyPlugins) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
328 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
329 MemoryBuffer answerHeaders; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
330 uint16_t httpStatus; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
331 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
332 PluginHttpHeaders headers(httpHeaders); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
333 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
334 return CheckHttp(OrthancPluginCallRestApi(GetGlobalContext(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
335 &buffer_, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
336 *answerHeaders, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
337 &httpStatus, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
338 OrthancPluginHttpMethod_Post, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
339 uri.c_str(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
340 headers.GetSize(), headers.GetKeys(), headers.GetValues(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
341 body, bodySize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
342 applyPlugins)); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
343 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
344 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
345 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
346 bool MemoryBuffer::RestApiPost(const std::string& uri, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
347 const Json::Value& body, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
348 const std::map<std::string, std::string>& httpHeaders, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
349 bool applyPlugins) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
350 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
351 std::string s; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
352 WriteFastJson(s, body); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
353 return RestApiPost(uri, s.c_str(), s.size(), httpHeaders, applyPlugins); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
354 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
355 #endif |
22 | 356 |
357 bool MemoryBuffer::RestApiPut(const std::string& uri, | |
358 const void* body, | |
359 size_t bodySize, | |
360 bool applyPlugins) | |
361 { | |
362 Clear(); | |
363 | |
364 // Cast for compatibility with Orthanc SDK <= 1.5.6 | |
365 const char* b = reinterpret_cast<const char*>(body); | |
366 | |
367 if (applyPlugins) | |
368 { | |
369 return CheckHttp(OrthancPluginRestApiPutAfterPlugins(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); | |
370 } | |
371 else | |
372 { | |
373 return CheckHttp(OrthancPluginRestApiPut(GetGlobalContext(), &buffer_, uri.c_str(), b, bodySize)); | |
374 } | |
375 } | |
376 | |
377 | |
35 | 378 static bool ReadJsonInternal(Json::Value& target, |
379 const void* buffer, | |
380 size_t size, | |
381 bool collectComments) | |
382 { | |
383 #if JSONCPP_USE_DEPRECATED == 1 | |
384 Json::Reader reader; | |
385 return reader.parse(reinterpret_cast<const char*>(buffer), | |
386 reinterpret_cast<const char*>(buffer) + size, target, collectComments); | |
387 #else | |
388 Json::CharReaderBuilder builder; | |
389 builder.settings_["collectComments"] = collectComments; | |
390 | |
391 const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); | |
392 assert(reader.get() != NULL); | |
393 | |
394 JSONCPP_STRING err; | |
395 if (reader->parse(reinterpret_cast<const char*>(buffer), | |
396 reinterpret_cast<const char*>(buffer) + size, &target, &err)) | |
397 { | |
398 return true; | |
399 } | |
400 else | |
401 { | |
402 LogError("Cannot parse JSON: " + std::string(err)); | |
403 return false; | |
404 } | |
405 #endif | |
406 } | |
407 | |
408 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
409 bool ReadJson(Json::Value& target, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
410 const std::string& source) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
411 { |
32
3bd0ec7c5a7c
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
31
diff
changeset
|
412 return ReadJson(target, source.empty() ? NULL : source.c_str(), source.size()); |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
413 } |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
414 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
415 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
416 bool ReadJson(Json::Value& target, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
417 const void* buffer, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
418 size_t size) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
419 { |
35 | 420 return ReadJsonInternal(target, buffer, size, true); |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
421 } |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
422 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
423 |
35 | 424 bool ReadJsonWithoutComments(Json::Value& target, |
425 const std::string& source) | |
426 { | |
427 return ReadJsonWithoutComments(target, source.empty() ? NULL : source.c_str(), source.size()); | |
428 } | |
429 | |
430 | |
431 bool ReadJsonWithoutComments(Json::Value& target, | |
432 const void* buffer, | |
433 size_t size) | |
434 { | |
435 return ReadJsonInternal(target, buffer, size, false); | |
436 } | |
437 | |
438 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
439 void WriteFastJson(std::string& target, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
440 const Json::Value& source) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
441 { |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
442 #if JSONCPP_USE_DEPRECATED == 1 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
443 Json::FastWriter writer; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
444 target = writer.write(source); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
445 #else |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
446 Json::StreamWriterBuilder builder; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
447 builder.settings_["indentation"] = ""; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
448 target = Json::writeString(builder, source); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
449 #endif |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
450 } |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
451 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
452 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
453 void WriteStyledJson(std::string& target, |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
454 const Json::Value& source) |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
455 { |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
456 #if JSONCPP_USE_DEPRECATED == 1 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
457 Json::StyledWriter writer; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
458 target = writer.write(source); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
459 #else |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
460 Json::StreamWriterBuilder builder; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
461 builder.settings_["indentation"] = " "; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
462 target = Json::writeString(builder, source); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
463 #endif |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
464 } |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
465 |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
466 |
22 | 467 bool MemoryBuffer::RestApiPost(const std::string& uri, |
468 const Json::Value& body, | |
469 bool applyPlugins) | |
470 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
471 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
472 WriteFastJson(s, body); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
473 return RestApiPost(uri, s, applyPlugins); |
22 | 474 } |
475 | |
476 | |
477 bool MemoryBuffer::RestApiPut(const std::string& uri, | |
478 const Json::Value& body, | |
479 bool applyPlugins) | |
480 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
481 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
482 WriteFastJson(s, body); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
483 return RestApiPut(uri, s, applyPlugins); |
22 | 484 } |
485 | |
486 | |
487 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
488 OrthancPluginCreateDicomFlags flags) | |
489 { | |
490 Clear(); | |
491 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
492 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
493 WriteFastJson(s, tags); |
22 | 494 |
495 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), NULL, flags)); | |
496 } | |
497 | |
498 void MemoryBuffer::CreateDicom(const Json::Value& tags, | |
499 const OrthancImage& pixelData, | |
500 OrthancPluginCreateDicomFlags flags) | |
501 { | |
502 Clear(); | |
503 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
504 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
505 WriteFastJson(s, tags); |
22 | 506 |
507 Check(OrthancPluginCreateDicom(GetGlobalContext(), &buffer_, s.c_str(), pixelData.GetObject(), flags)); | |
508 } | |
509 | |
510 | |
511 void MemoryBuffer::ReadFile(const std::string& path) | |
512 { | |
513 Clear(); | |
514 Check(OrthancPluginReadFile(GetGlobalContext(), &buffer_, path.c_str())); | |
515 } | |
516 | |
517 | |
518 void MemoryBuffer::GetDicomQuery(const OrthancPluginWorklistQuery* query) | |
519 { | |
520 Clear(); | |
521 Check(OrthancPluginWorklistGetDicomQuery(GetGlobalContext(), &buffer_, query)); | |
522 } | |
523 | |
524 | |
525 void OrthancString::Assign(char* str) | |
526 { | |
527 Clear(); | |
528 | |
529 if (str != NULL) | |
530 { | |
531 str_ = str; | |
532 } | |
533 } | |
534 | |
535 | |
536 void OrthancString::Clear() | |
537 { | |
538 if (str_ != NULL) | |
539 { | |
540 OrthancPluginFreeString(GetGlobalContext(), str_); | |
541 str_ = NULL; | |
542 } | |
543 } | |
544 | |
545 | |
546 void OrthancString::ToString(std::string& target) const | |
547 { | |
548 if (str_ == NULL) | |
549 { | |
550 target.clear(); | |
551 } | |
552 else | |
553 { | |
554 target.assign(str_); | |
555 } | |
556 } | |
557 | |
558 | |
559 void OrthancString::ToJson(Json::Value& target) const | |
560 { | |
561 if (str_ == NULL) | |
562 { | |
563 LogError("Cannot convert an empty memory buffer to JSON"); | |
564 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
565 } | |
566 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
567 if (!ReadJson(target, str_)) |
22 | 568 { |
569 LogError("Cannot convert some memory buffer to JSON"); | |
570 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
571 } | |
572 } | |
573 | |
574 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
575 void OrthancString::ToJsonWithoutComments(Json::Value& target) const |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
576 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
577 if (str_ == NULL) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
578 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
579 LogError("Cannot convert an empty memory buffer to JSON"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
580 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
581 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
582 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
583 if (!ReadJsonWithoutComments(target, str_)) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
584 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
585 LogError("Cannot convert some memory buffer to JSON"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
586 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
587 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
588 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
589 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
590 |
22 | 591 void MemoryBuffer::DicomToJson(Json::Value& target, |
592 OrthancPluginDicomToJsonFormat format, | |
593 OrthancPluginDicomToJsonFlags flags, | |
594 uint32_t maxStringLength) | |
595 { | |
596 OrthancString str; | |
597 str.Assign(OrthancPluginDicomBufferToJson | |
598 (GetGlobalContext(), GetData(), GetSize(), format, flags, maxStringLength)); | |
599 str.ToJson(target); | |
600 } | |
601 | |
602 | |
603 bool MemoryBuffer::HttpGet(const std::string& url, | |
604 const std::string& username, | |
605 const std::string& password) | |
606 { | |
607 Clear(); | |
608 return CheckHttp(OrthancPluginHttpGet(GetGlobalContext(), &buffer_, url.c_str(), | |
609 username.empty() ? NULL : username.c_str(), | |
610 password.empty() ? NULL : password.c_str())); | |
611 } | |
612 | |
613 | |
614 bool MemoryBuffer::HttpPost(const std::string& url, | |
615 const std::string& body, | |
616 const std::string& username, | |
617 const std::string& password) | |
618 { | |
619 Clear(); | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
620 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
621 if (body.size() > 0xffffffffu) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
622 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
623 LogError("Cannot handle body size > 4GB"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
624 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
625 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
626 |
22 | 627 return CheckHttp(OrthancPluginHttpPost(GetGlobalContext(), &buffer_, url.c_str(), |
628 body.c_str(), body.size(), | |
629 username.empty() ? NULL : username.c_str(), | |
630 password.empty() ? NULL : password.c_str())); | |
631 } | |
632 | |
633 | |
634 bool MemoryBuffer::HttpPut(const std::string& url, | |
635 const std::string& body, | |
636 const std::string& username, | |
637 const std::string& password) | |
638 { | |
639 Clear(); | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
640 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
641 if (body.size() > 0xffffffffu) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
642 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
643 LogError("Cannot handle body size > 4GB"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
644 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
645 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
646 |
22 | 647 return CheckHttp(OrthancPluginHttpPut(GetGlobalContext(), &buffer_, url.c_str(), |
648 body.empty() ? NULL : body.c_str(), | |
649 body.size(), | |
650 username.empty() ? NULL : username.c_str(), | |
651 password.empty() ? NULL : password.c_str())); | |
652 } | |
653 | |
654 | |
655 void MemoryBuffer::GetDicomInstance(const std::string& instanceId) | |
656 { | |
657 Clear(); | |
658 Check(OrthancPluginGetDicomForInstance(GetGlobalContext(), &buffer_, instanceId.c_str())); | |
659 } | |
660 | |
661 | |
662 bool HttpDelete(const std::string& url, | |
663 const std::string& username, | |
664 const std::string& password) | |
665 { | |
666 OrthancPluginErrorCode error = OrthancPluginHttpDelete | |
667 (GetGlobalContext(), url.c_str(), | |
668 username.empty() ? NULL : username.c_str(), | |
669 password.empty() ? NULL : password.c_str()); | |
670 | |
671 if (error == OrthancPluginErrorCode_Success) | |
672 { | |
673 return true; | |
674 } | |
675 else if (error == OrthancPluginErrorCode_UnknownResource || | |
676 error == OrthancPluginErrorCode_InexistentItem) | |
677 { | |
678 return false; | |
679 } | |
680 else | |
681 { | |
682 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
683 } | |
684 } | |
685 | |
686 | |
687 void LogError(const std::string& message) | |
688 { | |
689 if (HasGlobalContext()) | |
690 { | |
691 OrthancPluginLogError(GetGlobalContext(), message.c_str()); | |
692 } | |
693 } | |
694 | |
695 | |
696 void LogWarning(const std::string& message) | |
697 { | |
698 if (HasGlobalContext()) | |
699 { | |
700 OrthancPluginLogWarning(GetGlobalContext(), message.c_str()); | |
701 } | |
702 } | |
703 | |
704 | |
705 void LogInfo(const std::string& message) | |
706 { | |
707 if (HasGlobalContext()) | |
708 { | |
709 OrthancPluginLogInfo(GetGlobalContext(), message.c_str()); | |
710 } | |
711 } | |
712 | |
713 | |
714 void OrthancConfiguration::LoadConfiguration() | |
715 { | |
716 OrthancString str; | |
717 str.Assign(OrthancPluginGetConfiguration(GetGlobalContext())); | |
718 | |
719 if (str.GetContent() == NULL) | |
720 { | |
721 LogError("Cannot access the Orthanc configuration"); | |
722 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
723 } | |
724 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
725 str.ToJsonWithoutComments(configuration_); |
22 | 726 |
727 if (configuration_.type() != Json::objectValue) | |
728 { | |
729 LogError("Unable to read the Orthanc configuration"); | |
730 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
731 } | |
732 } | |
733 | |
734 | |
735 OrthancConfiguration::OrthancConfiguration() | |
736 { | |
737 LoadConfiguration(); | |
738 } | |
739 | |
740 | |
741 OrthancConfiguration::OrthancConfiguration(bool loadConfiguration) | |
742 { | |
743 if (loadConfiguration) | |
744 { | |
745 LoadConfiguration(); | |
746 } | |
747 else | |
748 { | |
749 configuration_ = Json::objectValue; | |
750 } | |
751 } | |
752 | |
753 | |
754 std::string OrthancConfiguration::GetPath(const std::string& key) const | |
755 { | |
756 if (path_.empty()) | |
757 { | |
758 return key; | |
759 } | |
760 else | |
761 { | |
762 return path_ + "." + key; | |
763 } | |
764 } | |
765 | |
766 | |
767 bool OrthancConfiguration::IsSection(const std::string& key) const | |
768 { | |
769 assert(configuration_.type() == Json::objectValue); | |
770 | |
771 return (configuration_.isMember(key) && | |
772 configuration_[key].type() == Json::objectValue); | |
773 } | |
774 | |
775 | |
776 void OrthancConfiguration::GetSection(OrthancConfiguration& target, | |
777 const std::string& key) const | |
778 { | |
779 assert(configuration_.type() == Json::objectValue); | |
780 | |
781 target.path_ = GetPath(key); | |
782 | |
783 if (!configuration_.isMember(key)) | |
784 { | |
785 target.configuration_ = Json::objectValue; | |
786 } | |
787 else | |
788 { | |
789 if (configuration_[key].type() != Json::objectValue) | |
790 { | |
791 LogError("The configuration section \"" + target.path_ + | |
792 "\" is not an associative array as expected"); | |
793 | |
794 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
795 } | |
796 | |
797 target.configuration_ = configuration_[key]; | |
798 } | |
799 } | |
800 | |
801 | |
802 bool OrthancConfiguration::LookupStringValue(std::string& target, | |
803 const std::string& key) const | |
804 { | |
805 assert(configuration_.type() == Json::objectValue); | |
806 | |
807 if (!configuration_.isMember(key)) | |
808 { | |
809 return false; | |
810 } | |
811 | |
812 if (configuration_[key].type() != Json::stringValue) | |
813 { | |
814 LogError("The configuration option \"" + GetPath(key) + | |
815 "\" is not a string as expected"); | |
816 | |
817 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
818 } | |
819 | |
820 target = configuration_[key].asString(); | |
821 return true; | |
822 } | |
823 | |
824 | |
825 bool OrthancConfiguration::LookupIntegerValue(int& target, | |
826 const std::string& key) const | |
827 { | |
828 assert(configuration_.type() == Json::objectValue); | |
829 | |
830 if (!configuration_.isMember(key)) | |
831 { | |
832 return false; | |
833 } | |
834 | |
835 switch (configuration_[key].type()) | |
836 { | |
837 case Json::intValue: | |
838 target = configuration_[key].asInt(); | |
839 return true; | |
840 | |
841 case Json::uintValue: | |
842 target = configuration_[key].asUInt(); | |
843 return true; | |
844 | |
845 default: | |
846 LogError("The configuration option \"" + GetPath(key) + | |
847 "\" is not an integer as expected"); | |
848 | |
849 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
850 } | |
851 } | |
852 | |
853 | |
854 bool OrthancConfiguration::LookupUnsignedIntegerValue(unsigned int& target, | |
855 const std::string& key) const | |
856 { | |
857 int tmp; | |
858 if (!LookupIntegerValue(tmp, key)) | |
859 { | |
860 return false; | |
861 } | |
862 | |
863 if (tmp < 0) | |
864 { | |
865 LogError("The configuration option \"" + GetPath(key) + | |
866 "\" is not a positive integer as expected"); | |
867 | |
868 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
869 } | |
870 else | |
871 { | |
872 target = static_cast<unsigned int>(tmp); | |
873 return true; | |
874 } | |
875 } | |
876 | |
877 | |
878 bool OrthancConfiguration::LookupBooleanValue(bool& target, | |
879 const std::string& key) const | |
880 { | |
881 assert(configuration_.type() == Json::objectValue); | |
882 | |
883 if (!configuration_.isMember(key)) | |
884 { | |
885 return false; | |
886 } | |
887 | |
888 if (configuration_[key].type() != Json::booleanValue) | |
889 { | |
890 LogError("The configuration option \"" + GetPath(key) + | |
891 "\" is not a Boolean as expected"); | |
892 | |
893 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
894 } | |
895 | |
896 target = configuration_[key].asBool(); | |
897 return true; | |
898 } | |
899 | |
900 | |
901 bool OrthancConfiguration::LookupFloatValue(float& target, | |
902 const std::string& key) const | |
903 { | |
904 assert(configuration_.type() == Json::objectValue); | |
905 | |
906 if (!configuration_.isMember(key)) | |
907 { | |
908 return false; | |
909 } | |
910 | |
911 switch (configuration_[key].type()) | |
912 { | |
913 case Json::realValue: | |
914 target = configuration_[key].asFloat(); | |
915 return true; | |
916 | |
917 case Json::intValue: | |
918 target = static_cast<float>(configuration_[key].asInt()); | |
919 return true; | |
920 | |
921 case Json::uintValue: | |
922 target = static_cast<float>(configuration_[key].asUInt()); | |
923 return true; | |
924 | |
925 default: | |
926 LogError("The configuration option \"" + GetPath(key) + | |
927 "\" is not an integer as expected"); | |
928 | |
929 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
930 } | |
931 } | |
932 | |
933 | |
934 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, | |
935 const std::string& key, | |
936 bool allowSingleString) const | |
937 { | |
938 assert(configuration_.type() == Json::objectValue); | |
939 | |
940 target.clear(); | |
941 | |
942 if (!configuration_.isMember(key)) | |
943 { | |
944 return false; | |
945 } | |
946 | |
947 switch (configuration_[key].type()) | |
948 { | |
949 case Json::arrayValue: | |
950 { | |
951 bool ok = true; | |
952 | |
953 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) | |
954 { | |
955 if (configuration_[key][i].type() == Json::stringValue) | |
956 { | |
957 target.push_back(configuration_[key][i].asString()); | |
958 } | |
959 else | |
960 { | |
961 ok = false; | |
962 } | |
963 } | |
964 | |
965 if (ok) | |
966 { | |
967 return true; | |
968 } | |
969 | |
970 break; | |
971 } | |
972 | |
973 case Json::stringValue: | |
974 if (allowSingleString) | |
975 { | |
976 target.push_back(configuration_[key].asString()); | |
977 return true; | |
978 } | |
979 | |
980 break; | |
981 | |
982 default: | |
983 break; | |
984 } | |
985 | |
986 LogError("The configuration option \"" + GetPath(key) + | |
987 "\" is not a list of strings as expected"); | |
988 | |
989 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
990 } | |
991 | |
992 | |
993 bool OrthancConfiguration::LookupSetOfStrings(std::set<std::string>& target, | |
994 const std::string& key, | |
995 bool allowSingleString) const | |
996 { | |
997 std::list<std::string> lst; | |
998 | |
999 if (LookupListOfStrings(lst, key, allowSingleString)) | |
1000 { | |
1001 target.clear(); | |
1002 | |
1003 for (std::list<std::string>::const_iterator | |
1004 it = lst.begin(); it != lst.end(); ++it) | |
1005 { | |
1006 target.insert(*it); | |
1007 } | |
1008 | |
1009 return true; | |
1010 } | |
1011 else | |
1012 { | |
1013 return false; | |
1014 } | |
1015 } | |
1016 | |
1017 | |
1018 std::string OrthancConfiguration::GetStringValue(const std::string& key, | |
1019 const std::string& defaultValue) const | |
1020 { | |
1021 std::string tmp; | |
1022 if (LookupStringValue(tmp, key)) | |
1023 { | |
1024 return tmp; | |
1025 } | |
1026 else | |
1027 { | |
1028 return defaultValue; | |
1029 } | |
1030 } | |
1031 | |
1032 | |
1033 int OrthancConfiguration::GetIntegerValue(const std::string& key, | |
1034 int defaultValue) const | |
1035 { | |
1036 int tmp; | |
1037 if (LookupIntegerValue(tmp, key)) | |
1038 { | |
1039 return tmp; | |
1040 } | |
1041 else | |
1042 { | |
1043 return defaultValue; | |
1044 } | |
1045 } | |
1046 | |
1047 | |
1048 unsigned int OrthancConfiguration::GetUnsignedIntegerValue(const std::string& key, | |
1049 unsigned int defaultValue) const | |
1050 { | |
1051 unsigned int tmp; | |
1052 if (LookupUnsignedIntegerValue(tmp, key)) | |
1053 { | |
1054 return tmp; | |
1055 } | |
1056 else | |
1057 { | |
1058 return defaultValue; | |
1059 } | |
1060 } | |
1061 | |
1062 | |
1063 bool OrthancConfiguration::GetBooleanValue(const std::string& key, | |
1064 bool defaultValue) const | |
1065 { | |
1066 bool tmp; | |
1067 if (LookupBooleanValue(tmp, key)) | |
1068 { | |
1069 return tmp; | |
1070 } | |
1071 else | |
1072 { | |
1073 return defaultValue; | |
1074 } | |
1075 } | |
1076 | |
1077 | |
1078 float OrthancConfiguration::GetFloatValue(const std::string& key, | |
1079 float defaultValue) const | |
1080 { | |
1081 float tmp; | |
1082 if (LookupFloatValue(tmp, key)) | |
1083 { | |
1084 return tmp; | |
1085 } | |
1086 else | |
1087 { | |
1088 return defaultValue; | |
1089 } | |
1090 } | |
1091 | |
1092 | |
1093 void OrthancConfiguration::GetDictionary(std::map<std::string, std::string>& target, | |
1094 const std::string& key) const | |
1095 { | |
1096 assert(configuration_.type() == Json::objectValue); | |
1097 | |
1098 target.clear(); | |
1099 | |
1100 if (!configuration_.isMember(key)) | |
1101 { | |
1102 return; | |
1103 } | |
1104 | |
1105 if (configuration_[key].type() != Json::objectValue) | |
1106 { | |
1107 LogError("The configuration option \"" + GetPath(key) + | |
1108 "\" is not a string as expected"); | |
1109 | |
1110 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
1111 } | |
1112 | |
1113 Json::Value::Members members = configuration_[key].getMemberNames(); | |
1114 | |
1115 for (size_t i = 0; i < members.size(); i++) | |
1116 { | |
1117 const Json::Value& value = configuration_[key][members[i]]; | |
1118 | |
1119 if (value.type() == Json::stringValue) | |
1120 { | |
1121 target[members[i]] = value.asString(); | |
1122 } | |
1123 else | |
1124 { | |
1125 LogError("The configuration option \"" + GetPath(key) + | |
1126 "\" is not a dictionary mapping strings to strings"); | |
1127 | |
1128 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
1129 } | |
1130 } | |
1131 } | |
1132 | |
1133 | |
1134 void OrthancImage::Clear() | |
1135 { | |
1136 if (image_ != NULL) | |
1137 { | |
1138 OrthancPluginFreeImage(GetGlobalContext(), image_); | |
1139 image_ = NULL; | |
1140 } | |
1141 } | |
1142 | |
1143 | |
1144 void OrthancImage::CheckImageAvailable() const | |
1145 { | |
1146 if (image_ == NULL) | |
1147 { | |
1148 LogError("Trying to access a NULL image"); | |
1149 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1150 } | |
1151 } | |
1152 | |
1153 | |
1154 OrthancImage::OrthancImage() : | |
1155 image_(NULL) | |
1156 { | |
1157 } | |
1158 | |
1159 | |
1160 OrthancImage::OrthancImage(OrthancPluginImage* image) : | |
1161 image_(image) | |
1162 { | |
1163 } | |
1164 | |
1165 | |
1166 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
1167 uint32_t width, | |
1168 uint32_t height) | |
1169 { | |
1170 image_ = OrthancPluginCreateImage(GetGlobalContext(), format, width, height); | |
1171 | |
1172 if (image_ == NULL) | |
1173 { | |
1174 LogError("Cannot create an image"); | |
1175 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1176 } | |
1177 } | |
1178 | |
1179 | |
1180 OrthancImage::OrthancImage(OrthancPluginPixelFormat format, | |
1181 uint32_t width, | |
1182 uint32_t height, | |
1183 uint32_t pitch, | |
1184 void* buffer) | |
1185 { | |
1186 image_ = OrthancPluginCreateImageAccessor | |
1187 (GetGlobalContext(), format, width, height, pitch, buffer); | |
1188 | |
1189 if (image_ == NULL) | |
1190 { | |
1191 LogError("Cannot create an image accessor"); | |
1192 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1193 } | |
1194 } | |
1195 | |
1196 void OrthancImage::UncompressPngImage(const void* data, | |
1197 size_t size) | |
1198 { | |
1199 Clear(); | |
1200 | |
1201 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Png); | |
1202 | |
1203 if (image_ == NULL) | |
1204 { | |
1205 LogError("Cannot uncompress a PNG image"); | |
1206 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1207 } | |
1208 } | |
1209 | |
1210 | |
1211 void OrthancImage::UncompressJpegImage(const void* data, | |
1212 size_t size) | |
1213 { | |
1214 Clear(); | |
1215 image_ = OrthancPluginUncompressImage(GetGlobalContext(), data, size, OrthancPluginImageFormat_Jpeg); | |
1216 if (image_ == NULL) | |
1217 { | |
1218 LogError("Cannot uncompress a JPEG image"); | |
1219 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1220 } | |
1221 } | |
1222 | |
1223 | |
1224 void OrthancImage::DecodeDicomImage(const void* data, | |
1225 size_t size, | |
1226 unsigned int frame) | |
1227 { | |
1228 Clear(); | |
1229 image_ = OrthancPluginDecodeDicomImage(GetGlobalContext(), data, size, frame); | |
1230 if (image_ == NULL) | |
1231 { | |
1232 LogError("Cannot uncompress a DICOM image"); | |
1233 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1234 } | |
1235 } | |
1236 | |
1237 | |
1238 OrthancPluginPixelFormat OrthancImage::GetPixelFormat() const | |
1239 { | |
1240 CheckImageAvailable(); | |
1241 return OrthancPluginGetImagePixelFormat(GetGlobalContext(), image_); | |
1242 } | |
1243 | |
1244 | |
1245 unsigned int OrthancImage::GetWidth() const | |
1246 { | |
1247 CheckImageAvailable(); | |
1248 return OrthancPluginGetImageWidth(GetGlobalContext(), image_); | |
1249 } | |
1250 | |
1251 | |
1252 unsigned int OrthancImage::GetHeight() const | |
1253 { | |
1254 CheckImageAvailable(); | |
1255 return OrthancPluginGetImageHeight(GetGlobalContext(), image_); | |
1256 } | |
1257 | |
1258 | |
1259 unsigned int OrthancImage::GetPitch() const | |
1260 { | |
1261 CheckImageAvailable(); | |
1262 return OrthancPluginGetImagePitch(GetGlobalContext(), image_); | |
1263 } | |
1264 | |
1265 | |
1266 void* OrthancImage::GetBuffer() const | |
1267 { | |
1268 CheckImageAvailable(); | |
1269 return OrthancPluginGetImageBuffer(GetGlobalContext(), image_); | |
1270 } | |
1271 | |
1272 | |
1273 void OrthancImage::CompressPngImage(MemoryBuffer& target) const | |
1274 { | |
1275 CheckImageAvailable(); | |
1276 | |
1277 OrthancPlugins::MemoryBuffer answer; | |
1278 OrthancPluginCompressPngImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
1279 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | |
1280 | |
1281 target.Swap(answer); | |
1282 } | |
1283 | |
1284 | |
1285 void OrthancImage::CompressJpegImage(MemoryBuffer& target, | |
1286 uint8_t quality) const | |
1287 { | |
1288 CheckImageAvailable(); | |
1289 | |
1290 OrthancPlugins::MemoryBuffer answer; | |
1291 OrthancPluginCompressJpegImage(GetGlobalContext(), *answer, GetPixelFormat(), | |
1292 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | |
1293 | |
1294 target.Swap(answer); | |
1295 } | |
1296 | |
1297 | |
1298 void OrthancImage::AnswerPngImage(OrthancPluginRestOutput* output) const | |
1299 { | |
1300 CheckImageAvailable(); | |
1301 OrthancPluginCompressAndAnswerPngImage(GetGlobalContext(), output, GetPixelFormat(), | |
1302 GetWidth(), GetHeight(), GetPitch(), GetBuffer()); | |
1303 } | |
1304 | |
1305 | |
1306 void OrthancImage::AnswerJpegImage(OrthancPluginRestOutput* output, | |
1307 uint8_t quality) const | |
1308 { | |
1309 CheckImageAvailable(); | |
1310 OrthancPluginCompressAndAnswerJpegImage(GetGlobalContext(), output, GetPixelFormat(), | |
1311 GetWidth(), GetHeight(), GetPitch(), GetBuffer(), quality); | |
1312 } | |
1313 | |
1314 | |
1315 OrthancPluginImage* OrthancImage::Release() | |
1316 { | |
1317 CheckImageAvailable(); | |
1318 OrthancPluginImage* tmp = image_; | |
1319 image_ = NULL; | |
1320 return tmp; | |
1321 } | |
1322 | |
1323 | |
1324 #if HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 | |
1325 FindMatcher::FindMatcher(const OrthancPluginWorklistQuery* worklist) : | |
1326 matcher_(NULL), | |
1327 worklist_(worklist) | |
1328 { | |
1329 if (worklist_ == NULL) | |
1330 { | |
1331 ORTHANC_PLUGINS_THROW_EXCEPTION(ParameterOutOfRange); | |
1332 } | |
1333 } | |
1334 | |
1335 | |
1336 void FindMatcher::SetupDicom(const void* query, | |
1337 uint32_t size) | |
1338 { | |
1339 worklist_ = NULL; | |
1340 | |
1341 matcher_ = OrthancPluginCreateFindMatcher(GetGlobalContext(), query, size); | |
1342 if (matcher_ == NULL) | |
1343 { | |
1344 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1345 } | |
1346 } | |
1347 | |
1348 | |
1349 FindMatcher::~FindMatcher() | |
1350 { | |
1351 // The "worklist_" field | |
1352 | |
1353 if (matcher_ != NULL) | |
1354 { | |
1355 OrthancPluginFreeFindMatcher(GetGlobalContext(), matcher_); | |
1356 } | |
1357 } | |
1358 | |
1359 | |
1360 | |
1361 bool FindMatcher::IsMatch(const void* dicom, | |
1362 uint32_t size) const | |
1363 { | |
1364 int32_t result; | |
1365 | |
1366 if (matcher_ != NULL) | |
1367 { | |
1368 result = OrthancPluginFindMatcherIsMatch(GetGlobalContext(), matcher_, dicom, size); | |
1369 } | |
1370 else if (worklist_ != NULL) | |
1371 { | |
1372 result = OrthancPluginWorklistIsMatch(GetGlobalContext(), worklist_, dicom, size); | |
1373 } | |
1374 else | |
1375 { | |
1376 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1377 } | |
1378 | |
1379 if (result == 0) | |
1380 { | |
1381 return false; | |
1382 } | |
1383 else if (result == 1) | |
1384 { | |
1385 return true; | |
1386 } | |
1387 else | |
1388 { | |
1389 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
1390 } | |
1391 } | |
1392 | |
1393 #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ | |
1394 | |
1395 void AnswerJson(const Json::Value& value, | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1396 OrthancPluginRestOutput* output) |
22 | 1397 { |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1398 std::string bodyString; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1399 WriteStyledJson(bodyString, value); |
22 | 1400 OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); |
1401 } | |
1402 | |
1403 void AnswerString(const std::string& answer, | |
1404 const char* mimeType, | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1405 OrthancPluginRestOutput* output) |
22 | 1406 { |
1407 OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); | |
1408 } | |
1409 | |
1410 void AnswerHttpError(uint16_t httpError, OrthancPluginRestOutput *output) | |
1411 { | |
1412 OrthancPluginSendHttpStatusCode(GetGlobalContext(), output, httpError); | |
1413 } | |
1414 | |
1415 void AnswerMethodNotAllowed(OrthancPluginRestOutput *output, const char* allowedMethods) | |
1416 { | |
1417 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowedMethods); | |
1418 } | |
1419 | |
1420 bool RestApiGetString(std::string& result, | |
1421 const std::string& uri, | |
1422 bool applyPlugins) | |
1423 { | |
1424 MemoryBuffer answer; | |
1425 if (!answer.RestApiGet(uri, applyPlugins)) | |
1426 { | |
1427 return false; | |
1428 } | |
1429 else | |
1430 { | |
1431 answer.ToString(result); | |
1432 return true; | |
1433 } | |
1434 } | |
1435 | |
1436 bool RestApiGetString(std::string& result, | |
1437 const std::string& uri, | |
1438 const std::map<std::string, std::string>& httpHeaders, | |
1439 bool applyPlugins) | |
1440 { | |
1441 MemoryBuffer answer; | |
1442 if (!answer.RestApiGet(uri, httpHeaders, applyPlugins)) | |
1443 { | |
1444 return false; | |
1445 } | |
1446 else | |
1447 { | |
1448 answer.ToString(result); | |
1449 return true; | |
1450 } | |
1451 } | |
1452 | |
1453 | |
1454 | |
1455 bool RestApiGet(Json::Value& result, | |
1456 const std::string& uri, | |
1457 bool applyPlugins) | |
1458 { | |
1459 MemoryBuffer answer; | |
1460 | |
1461 if (!answer.RestApiGet(uri, applyPlugins)) | |
1462 { | |
1463 return false; | |
1464 } | |
1465 else | |
1466 { | |
1467 if (!answer.IsEmpty()) | |
1468 { | |
1469 answer.ToJson(result); | |
1470 } | |
1471 return true; | |
1472 } | |
1473 } | |
1474 | |
1475 | |
1476 bool RestApiPost(std::string& result, | |
1477 const std::string& uri, | |
1478 const void* body, | |
1479 size_t bodySize, | |
1480 bool applyPlugins) | |
1481 { | |
1482 MemoryBuffer answer; | |
1483 | |
1484 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) | |
1485 { | |
1486 return false; | |
1487 } | |
1488 else | |
1489 { | |
1490 if (!answer.IsEmpty()) | |
1491 { | |
1492 result.assign(answer.GetData(), answer.GetSize()); | |
1493 } | |
1494 return true; | |
1495 } | |
1496 } | |
1497 | |
1498 | |
1499 bool RestApiPost(Json::Value& result, | |
1500 const std::string& uri, | |
1501 const void* body, | |
1502 size_t bodySize, | |
1503 bool applyPlugins) | |
1504 { | |
1505 MemoryBuffer answer; | |
1506 | |
1507 if (!answer.RestApiPost(uri, body, bodySize, applyPlugins)) | |
1508 { | |
1509 return false; | |
1510 } | |
1511 else | |
1512 { | |
1513 if (!answer.IsEmpty()) | |
1514 { | |
1515 answer.ToJson(result); | |
1516 } | |
1517 return true; | |
1518 } | |
1519 } | |
1520 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1521 #if HAS_ORTHANC_PLUGIN_GENERIC_CALL_REST_API == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1522 bool RestApiPost(Json::Value& result, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1523 const std::string& uri, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1524 const Json::Value& body, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1525 const std::map<std::string, std::string>& httpHeaders, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1526 bool applyPlugins) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1527 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1528 MemoryBuffer answer; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1529 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1530 if (!answer.RestApiPost(uri, body, httpHeaders, applyPlugins)) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1531 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1532 return false; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1533 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1534 else |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1535 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1536 if (!answer.IsEmpty()) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1537 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1538 answer.ToJson(result); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1539 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1540 return true; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1541 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1542 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1543 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1544 |
22 | 1545 |
1546 bool RestApiPost(Json::Value& result, | |
1547 const std::string& uri, | |
1548 const Json::Value& body, | |
1549 bool applyPlugins) | |
1550 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1551 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1552 WriteFastJson(s, body); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1553 return RestApiPost(result, uri, s, applyPlugins); |
22 | 1554 } |
1555 | |
1556 | |
1557 bool RestApiPut(Json::Value& result, | |
1558 const std::string& uri, | |
1559 const void* body, | |
1560 size_t bodySize, | |
1561 bool applyPlugins) | |
1562 { | |
1563 MemoryBuffer answer; | |
1564 | |
1565 if (!answer.RestApiPut(uri, body, bodySize, applyPlugins)) | |
1566 { | |
1567 return false; | |
1568 } | |
1569 else | |
1570 { | |
1571 if (!answer.IsEmpty()) // i.e, on a PUT to metadata/..., orthanc returns an empty response | |
1572 { | |
1573 answer.ToJson(result); | |
1574 } | |
1575 return true; | |
1576 } | |
1577 } | |
1578 | |
1579 | |
1580 bool RestApiPut(Json::Value& result, | |
1581 const std::string& uri, | |
1582 const Json::Value& body, | |
1583 bool applyPlugins) | |
1584 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1585 std::string s; |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1586 WriteFastJson(s, body); |
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
1587 return RestApiPut(result, uri, s, applyPlugins); |
22 | 1588 } |
1589 | |
1590 | |
1591 bool RestApiDelete(const std::string& uri, | |
1592 bool applyPlugins) | |
1593 { | |
1594 OrthancPluginErrorCode error; | |
1595 | |
1596 if (applyPlugins) | |
1597 { | |
1598 error = OrthancPluginRestApiDeleteAfterPlugins(GetGlobalContext(), uri.c_str()); | |
1599 } | |
1600 else | |
1601 { | |
1602 error = OrthancPluginRestApiDelete(GetGlobalContext(), uri.c_str()); | |
1603 } | |
1604 | |
1605 if (error == OrthancPluginErrorCode_Success) | |
1606 { | |
1607 return true; | |
1608 } | |
1609 else if (error == OrthancPluginErrorCode_UnknownResource || | |
1610 error == OrthancPluginErrorCode_InexistentItem) | |
1611 { | |
1612 return false; | |
1613 } | |
1614 else | |
1615 { | |
1616 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
1617 } | |
1618 } | |
1619 | |
1620 | |
1621 void ReportMinimalOrthancVersion(unsigned int major, | |
1622 unsigned int minor, | |
1623 unsigned int revision) | |
1624 { | |
1625 LogError("Your version of the Orthanc core (" + | |
1626 std::string(GetGlobalContext()->orthancVersion) + | |
1627 ") is too old to run this plugin (version " + | |
1628 boost::lexical_cast<std::string>(major) + "." + | |
1629 boost::lexical_cast<std::string>(minor) + "." + | |
1630 boost::lexical_cast<std::string>(revision) + | |
1631 " is required)"); | |
1632 } | |
1633 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1634 bool CheckMinimalVersion(const char* version, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1635 unsigned int major, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1636 unsigned int minor, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1637 unsigned int revision) |
22 | 1638 { |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1639 if (!strcmp(version, "mainline")) |
22 | 1640 { |
1641 // Assume compatibility with the mainline | |
1642 return true; | |
1643 } | |
1644 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1645 // Parse the version |
22 | 1646 int aa, bb, cc; |
1647 if ( | |
1648 #ifdef _MSC_VER | |
1649 sscanf_s | |
1650 #else | |
1651 sscanf | |
1652 #endif | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1653 (version, "%4d.%4d.%4d", &aa, &bb, &cc) != 3 || |
22 | 1654 aa < 0 || |
1655 bb < 0 || | |
1656 cc < 0) | |
1657 { | |
1658 return false; | |
1659 } | |
1660 | |
1661 unsigned int a = static_cast<unsigned int>(aa); | |
1662 unsigned int b = static_cast<unsigned int>(bb); | |
1663 unsigned int c = static_cast<unsigned int>(cc); | |
1664 | |
1665 // Check the major version number | |
1666 | |
1667 if (a > major) | |
1668 { | |
1669 return true; | |
1670 } | |
1671 | |
1672 if (a < major) | |
1673 { | |
1674 return false; | |
1675 } | |
1676 | |
1677 // Check the minor version number | |
1678 assert(a == major); | |
1679 | |
1680 if (b > minor) | |
1681 { | |
1682 return true; | |
1683 } | |
1684 | |
1685 if (b < minor) | |
1686 { | |
1687 return false; | |
1688 } | |
1689 | |
1690 // Check the patch level version number | |
1691 assert(a == major && b == minor); | |
1692 | |
1693 if (c >= revision) | |
1694 { | |
1695 return true; | |
1696 } | |
1697 else | |
1698 { | |
1699 return false; | |
1700 } | |
1701 } | |
1702 | |
1703 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1704 bool CheckMinimalOrthancVersion(unsigned int major, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1705 unsigned int minor, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1706 unsigned int revision) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1707 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1708 if (!HasGlobalContext()) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1709 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1710 LogError("Bad Orthanc context in the plugin"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1711 return false; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1712 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1713 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1714 return CheckMinimalVersion(GetGlobalContext()->orthancVersion, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1715 major, minor, revision); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1716 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1717 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
1718 |
22 | 1719 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 5, 0) |
1720 const char* AutodetectMimeType(const std::string& path) | |
1721 { | |
1722 const char* mime = OrthancPluginAutodetectMimeType(GetGlobalContext(), path.c_str()); | |
1723 | |
1724 if (mime == NULL) | |
1725 { | |
1726 // Should never happen, just for safety | |
1727 return "application/octet-stream"; | |
1728 } | |
1729 else | |
1730 { | |
1731 return mime; | |
1732 } | |
1733 } | |
1734 #endif | |
1735 | |
1736 | |
1737 #if HAS_ORTHANC_PLUGIN_PEERS == 1 | |
1738 size_t OrthancPeers::GetPeerIndex(const std::string& name) const | |
1739 { | |
1740 size_t index; | |
1741 if (LookupName(index, name)) | |
1742 { | |
1743 return index; | |
1744 } | |
1745 else | |
1746 { | |
1747 LogError("Inexistent peer: " + name); | |
1748 ORTHANC_PLUGINS_THROW_EXCEPTION(UnknownResource); | |
1749 } | |
1750 } | |
1751 | |
1752 | |
1753 OrthancPeers::OrthancPeers() : | |
1754 peers_(NULL), | |
1755 timeout_(0) | |
1756 { | |
1757 peers_ = OrthancPluginGetPeers(GetGlobalContext()); | |
1758 | |
1759 if (peers_ == NULL) | |
1760 { | |
1761 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1762 } | |
1763 | |
1764 uint32_t count = OrthancPluginGetPeersCount(GetGlobalContext(), peers_); | |
1765 | |
1766 for (uint32_t i = 0; i < count; i++) | |
1767 { | |
1768 const char* name = OrthancPluginGetPeerName(GetGlobalContext(), peers_, i); | |
1769 if (name == NULL) | |
1770 { | |
1771 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1772 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1773 } | |
1774 | |
1775 index_[name] = i; | |
1776 } | |
1777 } | |
1778 | |
1779 | |
1780 OrthancPeers::~OrthancPeers() | |
1781 { | |
1782 if (peers_ != NULL) | |
1783 { | |
1784 OrthancPluginFreePeers(GetGlobalContext(), peers_); | |
1785 } | |
1786 } | |
1787 | |
1788 | |
1789 bool OrthancPeers::LookupName(size_t& target, | |
1790 const std::string& name) const | |
1791 { | |
1792 Index::const_iterator found = index_.find(name); | |
1793 | |
1794 if (found == index_.end()) | |
1795 { | |
1796 return false; | |
1797 } | |
1798 else | |
1799 { | |
1800 target = found->second; | |
1801 return true; | |
1802 } | |
1803 } | |
1804 | |
1805 | |
1806 std::string OrthancPeers::GetPeerName(size_t index) const | |
1807 { | |
1808 if (index >= index_.size()) | |
1809 { | |
1810 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1811 } | |
1812 else | |
1813 { | |
1814 const char* s = OrthancPluginGetPeerName(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1815 if (s == NULL) | |
1816 { | |
1817 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1818 } | |
1819 else | |
1820 { | |
1821 return s; | |
1822 } | |
1823 } | |
1824 } | |
1825 | |
1826 | |
1827 std::string OrthancPeers::GetPeerUrl(size_t index) const | |
1828 { | |
1829 if (index >= index_.size()) | |
1830 { | |
1831 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1832 } | |
1833 else | |
1834 { | |
1835 const char* s = OrthancPluginGetPeerUrl(GetGlobalContext(), peers_, static_cast<uint32_t>(index)); | |
1836 if (s == NULL) | |
1837 { | |
1838 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
1839 } | |
1840 else | |
1841 { | |
1842 return s; | |
1843 } | |
1844 } | |
1845 } | |
1846 | |
1847 | |
1848 std::string OrthancPeers::GetPeerUrl(const std::string& name) const | |
1849 { | |
1850 return GetPeerUrl(GetPeerIndex(name)); | |
1851 } | |
1852 | |
1853 | |
1854 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1855 size_t index, | |
1856 const std::string& key) const | |
1857 { | |
1858 if (index >= index_.size()) | |
1859 { | |
1860 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1861 } | |
1862 else | |
1863 { | |
1864 const char* s = OrthancPluginGetPeerUserProperty(GetGlobalContext(), peers_, static_cast<uint32_t>(index), key.c_str()); | |
1865 if (s == NULL) | |
1866 { | |
1867 return false; | |
1868 } | |
1869 else | |
1870 { | |
1871 value.assign(s); | |
1872 return true; | |
1873 } | |
1874 } | |
1875 } | |
1876 | |
1877 | |
1878 bool OrthancPeers::LookupUserProperty(std::string& value, | |
1879 const std::string& peer, | |
1880 const std::string& key) const | |
1881 { | |
1882 return LookupUserProperty(value, GetPeerIndex(peer), key); | |
1883 } | |
1884 | |
1885 | |
1886 bool OrthancPeers::DoGet(MemoryBuffer& target, | |
1887 size_t index, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1888 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1889 const std::map<std::string, std::string>& headers) const |
22 | 1890 { |
1891 if (index >= index_.size()) | |
1892 { | |
1893 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
1894 } | |
1895 | |
1896 OrthancPlugins::MemoryBuffer answer; | |
1897 uint16_t status; | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1898 PluginHttpHeaders pluginHeaders(headers); |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1899 |
22 | 1900 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
1901 (GetGlobalContext(), *answer, NULL, &status, peers_, | |
1902 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Get, uri.c_str(), | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1903 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_); |
22 | 1904 |
1905 if (code == OrthancPluginErrorCode_Success) | |
1906 { | |
1907 target.Swap(answer); | |
1908 return (status == 200); | |
1909 } | |
1910 else | |
1911 { | |
1912 return false; | |
1913 } | |
1914 } | |
1915 | |
1916 | |
1917 bool OrthancPeers::DoGet(MemoryBuffer& target, | |
1918 const std::string& name, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1919 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1920 const std::map<std::string, std::string>& headers) const |
22 | 1921 { |
1922 size_t index; | |
1923 return (LookupName(index, name) && | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1924 DoGet(target, index, uri, headers)); |
22 | 1925 } |
1926 | |
1927 | |
1928 bool OrthancPeers::DoGet(Json::Value& target, | |
1929 size_t index, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1930 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1931 const std::map<std::string, std::string>& headers) const |
22 | 1932 { |
1933 MemoryBuffer buffer; | |
1934 | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1935 if (DoGet(buffer, index, uri, headers)) |
22 | 1936 { |
1937 buffer.ToJson(target); | |
1938 return true; | |
1939 } | |
1940 else | |
1941 { | |
1942 return false; | |
1943 } | |
1944 } | |
1945 | |
1946 | |
1947 bool OrthancPeers::DoGet(Json::Value& target, | |
1948 const std::string& name, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1949 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1950 const std::map<std::string, std::string>& headers) const |
22 | 1951 { |
1952 MemoryBuffer buffer; | |
1953 | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1954 if (DoGet(buffer, name, uri, headers)) |
22 | 1955 { |
1956 buffer.ToJson(target); | |
1957 return true; | |
1958 } | |
1959 else | |
1960 { | |
1961 return false; | |
1962 } | |
1963 } | |
1964 | |
1965 | |
1966 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
1967 const std::string& name, | |
1968 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1969 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1970 const std::map<std::string, std::string>& headers) const |
22 | 1971 { |
1972 size_t index; | |
1973 return (LookupName(index, name) && | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1974 DoPost(target, index, uri, body, headers)); |
22 | 1975 } |
1976 | |
1977 | |
1978 bool OrthancPeers::DoPost(Json::Value& target, | |
1979 size_t index, | |
1980 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1981 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1982 const std::map<std::string, std::string>& headers) const |
22 | 1983 { |
1984 MemoryBuffer buffer; | |
1985 | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
1986 if (DoPost(buffer, index, uri, body, headers)) |
22 | 1987 { |
1988 buffer.ToJson(target); | |
1989 return true; | |
1990 } | |
1991 else | |
1992 { | |
1993 return false; | |
1994 } | |
1995 } | |
1996 | |
1997 | |
1998 bool OrthancPeers::DoPost(Json::Value& target, | |
1999 const std::string& name, | |
2000 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2001 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2002 const std::map<std::string, std::string>& headers) const |
22 | 2003 { |
2004 MemoryBuffer buffer; | |
2005 | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2006 if (DoPost(buffer, name, uri, body, headers)) |
22 | 2007 { |
2008 buffer.ToJson(target); | |
2009 return true; | |
2010 } | |
2011 else | |
2012 { | |
2013 return false; | |
2014 } | |
2015 } | |
2016 | |
2017 | |
2018 bool OrthancPeers::DoPost(MemoryBuffer& target, | |
2019 size_t index, | |
2020 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2021 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2022 const std::map<std::string, std::string>& headers) const |
22 | 2023 { |
2024 if (index >= index_.size()) | |
2025 { | |
2026 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2027 } | |
2028 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2029 if (body.size() > 0xffffffffu) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2030 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2031 LogError("Cannot handle body size > 4GB"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2032 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2033 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2034 |
22 | 2035 OrthancPlugins::MemoryBuffer answer; |
2036 uint16_t status; | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2037 PluginHttpHeaders pluginHeaders(headers); |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2038 |
22 | 2039 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2040 (GetGlobalContext(), *answer, NULL, &status, peers_, | |
2041 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Post, uri.c_str(), | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2042 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
22 | 2043 |
2044 if (code == OrthancPluginErrorCode_Success) | |
2045 { | |
2046 target.Swap(answer); | |
2047 return (status == 200); | |
2048 } | |
2049 else | |
2050 { | |
2051 return false; | |
2052 } | |
2053 } | |
2054 | |
2055 | |
2056 bool OrthancPeers::DoPut(size_t index, | |
2057 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2058 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2059 const std::map<std::string, std::string>& headers) const |
22 | 2060 { |
2061 if (index >= index_.size()) | |
2062 { | |
2063 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2064 } | |
2065 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2066 if (body.size() > 0xffffffffu) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2067 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2068 LogError("Cannot handle body size > 4GB"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2069 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2070 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2071 |
22 | 2072 OrthancPlugins::MemoryBuffer answer; |
2073 uint16_t status; | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2074 PluginHttpHeaders pluginHeaders(headers); |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2075 |
22 | 2076 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2077 (GetGlobalContext(), *answer, NULL, &status, peers_, | |
2078 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Put, uri.c_str(), | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2079 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), body.empty() ? NULL : body.c_str(), body.size(), timeout_); |
22 | 2080 |
2081 if (code == OrthancPluginErrorCode_Success) | |
2082 { | |
2083 return (status == 200); | |
2084 } | |
2085 else | |
2086 { | |
2087 return false; | |
2088 } | |
2089 } | |
2090 | |
2091 | |
2092 bool OrthancPeers::DoPut(const std::string& name, | |
2093 const std::string& uri, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2094 const std::string& body, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2095 const std::map<std::string, std::string>& headers) const |
22 | 2096 { |
2097 size_t index; | |
2098 return (LookupName(index, name) && | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2099 DoPut(index, uri, body, headers)); |
22 | 2100 } |
2101 | |
2102 | |
2103 bool OrthancPeers::DoDelete(size_t index, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2104 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2105 const std::map<std::string, std::string>& headers) const |
22 | 2106 { |
2107 if (index >= index_.size()) | |
2108 { | |
2109 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2110 } | |
2111 | |
2112 OrthancPlugins::MemoryBuffer answer; | |
2113 uint16_t status; | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2114 PluginHttpHeaders pluginHeaders(headers); |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2115 |
22 | 2116 OrthancPluginErrorCode code = OrthancPluginCallPeerApi |
2117 (GetGlobalContext(), *answer, NULL, &status, peers_, | |
2118 static_cast<uint32_t>(index), OrthancPluginHttpMethod_Delete, uri.c_str(), | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2119 pluginHeaders.GetSize(), pluginHeaders.GetKeys(), pluginHeaders.GetValues(), NULL, 0, timeout_); |
22 | 2120 |
2121 if (code == OrthancPluginErrorCode_Success) | |
2122 { | |
2123 return (status == 200); | |
2124 } | |
2125 else | |
2126 { | |
2127 return false; | |
2128 } | |
2129 } | |
2130 | |
2131 | |
2132 bool OrthancPeers::DoDelete(const std::string& name, | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2133 const std::string& uri, |
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2134 const std::map<std::string, std::string>& headers) const |
22 | 2135 { |
2136 size_t index; | |
2137 return (LookupName(index, name) && | |
44
f4e828607f02
Added 'SenderTransferID' option that is added as an HTTP header in outgoing requests in PushMode
Alain Mazy <am@osimis.io>
parents:
40
diff
changeset
|
2138 DoDelete(index, uri, headers)); |
22 | 2139 } |
2140 #endif | |
2141 | |
2142 | |
2143 | |
2144 | |
2145 | |
2146 /****************************************************************** | |
2147 ** JOBS | |
2148 ******************************************************************/ | |
2149 | |
2150 #if HAS_ORTHANC_PLUGIN_JOB == 1 | |
2151 void OrthancJob::CallbackFinalize(void* job) | |
2152 { | |
2153 if (job != NULL) | |
2154 { | |
2155 delete reinterpret_cast<OrthancJob*>(job); | |
2156 } | |
2157 } | |
2158 | |
2159 | |
2160 float OrthancJob::CallbackGetProgress(void* job) | |
2161 { | |
2162 assert(job != NULL); | |
2163 | |
2164 try | |
2165 { | |
2166 return reinterpret_cast<OrthancJob*>(job)->progress_; | |
2167 } | |
2168 catch (...) | |
2169 { | |
2170 return 0; | |
2171 } | |
2172 } | |
2173 | |
2174 | |
2175 const char* OrthancJob::CallbackGetContent(void* job) | |
2176 { | |
2177 assert(job != NULL); | |
2178 | |
2179 try | |
2180 { | |
2181 return reinterpret_cast<OrthancJob*>(job)->content_.c_str(); | |
2182 } | |
2183 catch (...) | |
2184 { | |
2185 return 0; | |
2186 } | |
2187 } | |
2188 | |
2189 | |
2190 const char* OrthancJob::CallbackGetSerialized(void* job) | |
2191 { | |
2192 assert(job != NULL); | |
2193 | |
2194 try | |
2195 { | |
2196 const OrthancJob& tmp = *reinterpret_cast<OrthancJob*>(job); | |
2197 | |
2198 if (tmp.hasSerialized_) | |
2199 { | |
2200 return tmp.serialized_.c_str(); | |
2201 } | |
2202 else | |
2203 { | |
2204 return NULL; | |
2205 } | |
2206 } | |
2207 catch (...) | |
2208 { | |
2209 return 0; | |
2210 } | |
2211 } | |
2212 | |
2213 | |
2214 OrthancPluginJobStepStatus OrthancJob::CallbackStep(void* job) | |
2215 { | |
2216 assert(job != NULL); | |
2217 | |
2218 try | |
2219 { | |
2220 return reinterpret_cast<OrthancJob*>(job)->Step(); | |
2221 } | |
2222 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS&) | |
2223 { | |
2224 return OrthancPluginJobStepStatus_Failure; | |
2225 } | |
2226 catch (...) | |
2227 { | |
2228 return OrthancPluginJobStepStatus_Failure; | |
2229 } | |
2230 } | |
2231 | |
2232 | |
2233 OrthancPluginErrorCode OrthancJob::CallbackStop(void* job, | |
2234 OrthancPluginJobStopReason reason) | |
2235 { | |
2236 assert(job != NULL); | |
2237 | |
2238 try | |
2239 { | |
2240 reinterpret_cast<OrthancJob*>(job)->Stop(reason); | |
2241 return OrthancPluginErrorCode_Success; | |
2242 } | |
2243 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2244 { | |
2245 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2246 } | |
2247 catch (...) | |
2248 { | |
2249 return OrthancPluginErrorCode_Plugin; | |
2250 } | |
2251 } | |
2252 | |
2253 | |
2254 OrthancPluginErrorCode OrthancJob::CallbackReset(void* job) | |
2255 { | |
2256 assert(job != NULL); | |
2257 | |
2258 try | |
2259 { | |
2260 reinterpret_cast<OrthancJob*>(job)->Reset(); | |
2261 return OrthancPluginErrorCode_Success; | |
2262 } | |
2263 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2264 { | |
2265 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2266 } | |
2267 catch (...) | |
2268 { | |
2269 return OrthancPluginErrorCode_Plugin; | |
2270 } | |
2271 } | |
2272 | |
2273 | |
2274 void OrthancJob::ClearContent() | |
2275 { | |
2276 Json::Value empty = Json::objectValue; | |
2277 UpdateContent(empty); | |
2278 } | |
2279 | |
2280 | |
2281 void OrthancJob::UpdateContent(const Json::Value& content) | |
2282 { | |
2283 if (content.type() != Json::objectValue) | |
2284 { | |
2285 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
2286 } | |
2287 else | |
2288 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2289 WriteFastJson(content_, content); |
22 | 2290 } |
2291 } | |
2292 | |
2293 | |
2294 void OrthancJob::ClearSerialized() | |
2295 { | |
2296 hasSerialized_ = false; | |
2297 serialized_.clear(); | |
2298 } | |
2299 | |
2300 | |
2301 void OrthancJob::UpdateSerialized(const Json::Value& serialized) | |
2302 { | |
2303 if (serialized.type() != Json::objectValue) | |
2304 { | |
2305 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_BadFileFormat); | |
2306 } | |
2307 else | |
2308 { | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
2309 WriteFastJson(serialized_, serialized); |
22 | 2310 hasSerialized_ = true; |
2311 } | |
2312 } | |
2313 | |
2314 | |
2315 void OrthancJob::UpdateProgress(float progress) | |
2316 { | |
2317 if (progress < 0 || | |
2318 progress > 1) | |
2319 { | |
2320 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); | |
2321 } | |
2322 | |
2323 progress_ = progress; | |
2324 } | |
2325 | |
2326 | |
2327 OrthancJob::OrthancJob(const std::string& jobType) : | |
2328 jobType_(jobType), | |
2329 progress_(0) | |
2330 { | |
2331 ClearContent(); | |
2332 ClearSerialized(); | |
2333 } | |
2334 | |
2335 | |
2336 OrthancPluginJob* OrthancJob::Create(OrthancJob* job) | |
2337 { | |
2338 if (job == NULL) | |
2339 { | |
2340 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | |
2341 } | |
2342 | |
2343 OrthancPluginJob* orthanc = OrthancPluginCreateJob( | |
2344 GetGlobalContext(), job, CallbackFinalize, job->jobType_.c_str(), | |
2345 CallbackGetProgress, CallbackGetContent, CallbackGetSerialized, | |
2346 CallbackStep, CallbackStop, CallbackReset); | |
2347 | |
2348 if (orthanc == NULL) | |
2349 { | |
2350 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
2351 } | |
2352 else | |
2353 { | |
2354 return orthanc; | |
2355 } | |
2356 } | |
2357 | |
2358 | |
2359 std::string OrthancJob::Submit(OrthancJob* job, | |
2360 int priority) | |
2361 { | |
2362 if (job == NULL) | |
2363 { | |
2364 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_NullPointer); | |
2365 } | |
2366 | |
2367 OrthancPluginJob* orthanc = Create(job); | |
2368 | |
2369 char* id = OrthancPluginSubmitJob(GetGlobalContext(), orthanc, priority); | |
2370 | |
2371 if (id == NULL) | |
2372 { | |
2373 LogError("Plugin cannot submit job"); | |
2374 OrthancPluginFreeJob(GetGlobalContext(), orthanc); | |
2375 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_Plugin); | |
2376 } | |
2377 else | |
2378 { | |
2379 std::string tmp(id); | |
2380 tmp.assign(id); | |
2381 OrthancPluginFreeString(GetGlobalContext(), id); | |
2382 | |
2383 return tmp; | |
2384 } | |
2385 } | |
2386 | |
2387 | |
2388 void OrthancJob::SubmitAndWait(Json::Value& result, | |
2389 OrthancJob* job /* takes ownership */, | |
2390 int priority) | |
2391 { | |
2392 std::string id = Submit(job, priority); | |
2393 | |
2394 for (;;) | |
2395 { | |
2396 boost::this_thread::sleep(boost::posix_time::milliseconds(100)); | |
2397 | |
2398 Json::Value status; | |
2399 if (!RestApiGet(status, "/jobs/" + id, false) || | |
2400 !status.isMember("State") || | |
2401 status["State"].type() != Json::stringValue) | |
2402 { | |
2403 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InexistentItem); | |
2404 } | |
2405 | |
2406 const std::string state = status["State"].asString(); | |
2407 if (state == "Success") | |
2408 { | |
2409 if (status.isMember("Content")) | |
2410 { | |
2411 result = status["Content"]; | |
2412 } | |
2413 else | |
2414 { | |
2415 result = Json::objectValue; | |
2416 } | |
2417 | |
2418 return; | |
2419 } | |
2420 else if (state == "Running") | |
2421 { | |
2422 continue; | |
2423 } | |
2424 else if (!status.isMember("ErrorCode") || | |
2425 status["ErrorCode"].type() != Json::intValue) | |
2426 { | |
2427 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_InternalError); | |
2428 } | |
2429 else | |
2430 { | |
2431 if (!status.isMember("ErrorDescription") || | |
2432 status["ErrorDescription"].type() != Json::stringValue) | |
2433 { | |
2434 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); | |
2435 } | |
2436 else | |
2437 { | |
2438 #if HAS_ORTHANC_EXCEPTION == 1 | |
2439 throw Orthanc::OrthancException(static_cast<Orthanc::ErrorCode>(status["ErrorCode"].asInt()), | |
2440 status["ErrorDescription"].asString()); | |
2441 #else | |
2442 LogError("Exception while executing the job: " + status["ErrorDescription"].asString()); | |
2443 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(status["ErrorCode"].asInt()); | |
2444 #endif | |
2445 } | |
2446 } | |
2447 } | |
2448 } | |
2449 | |
2450 | |
2451 void OrthancJob::SubmitFromRestApiPost(OrthancPluginRestOutput* output, | |
2452 const Json::Value& body, | |
2453 OrthancJob* job) | |
2454 { | |
2455 static const char* KEY_SYNCHRONOUS = "Synchronous"; | |
2456 static const char* KEY_ASYNCHRONOUS = "Asynchronous"; | |
2457 static const char* KEY_PRIORITY = "Priority"; | |
2458 | |
2459 boost::movelib::unique_ptr<OrthancJob> protection(job); | |
2460 | |
2461 if (body.type() != Json::objectValue) | |
2462 { | |
2463 #if HAS_ORTHANC_EXCEPTION == 1 | |
2464 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | |
2465 "Expected a JSON object in the body"); | |
2466 #else | |
2467 LogError("Expected a JSON object in the body"); | |
2468 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2469 #endif | |
2470 } | |
2471 | |
2472 bool synchronous = true; | |
2473 | |
2474 if (body.isMember(KEY_SYNCHRONOUS)) | |
2475 { | |
2476 if (body[KEY_SYNCHRONOUS].type() != Json::booleanValue) | |
2477 { | |
2478 #if HAS_ORTHANC_EXCEPTION == 1 | |
2479 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | |
2480 "Option \"" + std::string(KEY_SYNCHRONOUS) + | |
2481 "\" must be Boolean"); | |
2482 #else | |
2483 LogError("Option \"" + std::string(KEY_SYNCHRONOUS) + "\" must be Boolean"); | |
2484 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2485 #endif | |
2486 } | |
2487 else | |
2488 { | |
2489 synchronous = body[KEY_SYNCHRONOUS].asBool(); | |
2490 } | |
2491 } | |
2492 | |
2493 if (body.isMember(KEY_ASYNCHRONOUS)) | |
2494 { | |
2495 if (body[KEY_ASYNCHRONOUS].type() != Json::booleanValue) | |
2496 { | |
2497 #if HAS_ORTHANC_EXCEPTION == 1 | |
2498 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | |
2499 "Option \"" + std::string(KEY_ASYNCHRONOUS) + | |
2500 "\" must be Boolean"); | |
2501 #else | |
2502 LogError("Option \"" + std::string(KEY_ASYNCHRONOUS) + "\" must be Boolean"); | |
2503 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2504 #endif | |
2505 } | |
2506 else | |
2507 { | |
2508 synchronous = !body[KEY_ASYNCHRONOUS].asBool(); | |
2509 } | |
2510 } | |
2511 | |
2512 int priority = 0; | |
2513 | |
2514 if (body.isMember(KEY_PRIORITY)) | |
2515 { | |
2516 if (body[KEY_PRIORITY].type() != Json::booleanValue) | |
2517 { | |
2518 #if HAS_ORTHANC_EXCEPTION == 1 | |
2519 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, | |
2520 "Option \"" + std::string(KEY_PRIORITY) + | |
2521 "\" must be an integer"); | |
2522 #else | |
2523 LogError("Option \"" + std::string(KEY_PRIORITY) + "\" must be an integer"); | |
2524 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
2525 #endif | |
2526 } | |
2527 else | |
2528 { | |
2529 priority = !body[KEY_PRIORITY].asInt(); | |
2530 } | |
2531 } | |
2532 | |
2533 Json::Value result; | |
2534 | |
2535 if (synchronous) | |
2536 { | |
2537 OrthancPlugins::OrthancJob::SubmitAndWait(result, protection.release(), priority); | |
2538 } | |
2539 else | |
2540 { | |
2541 std::string id = OrthancPlugins::OrthancJob::Submit(protection.release(), priority); | |
2542 | |
2543 result = Json::objectValue; | |
2544 result["ID"] = id; | |
2545 result["Path"] = "/jobs/" + id; | |
2546 } | |
2547 | |
2548 std::string s = result.toStyledString(); | |
2549 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), | |
2550 s.size(), "application/json"); | |
2551 } | |
2552 | |
2553 #endif | |
2554 | |
2555 | |
2556 | |
2557 | |
2558 /****************************************************************** | |
2559 ** METRICS | |
2560 ******************************************************************/ | |
2561 | |
2562 #if HAS_ORTHANC_PLUGIN_METRICS == 1 | |
2563 MetricsTimer::MetricsTimer(const char* name) : | |
2564 name_(name) | |
2565 { | |
2566 start_ = boost::posix_time::microsec_clock::universal_time(); | |
2567 } | |
2568 | |
2569 MetricsTimer::~MetricsTimer() | |
2570 { | |
2571 const boost::posix_time::ptime stop = boost::posix_time::microsec_clock::universal_time(); | |
2572 const boost::posix_time::time_duration diff = stop - start_; | |
2573 OrthancPluginSetMetricsValue(GetGlobalContext(), name_.c_str(), static_cast<float>(diff.total_milliseconds()), | |
2574 OrthancPluginMetricsType_Timer); | |
2575 } | |
2576 #endif | |
2577 | |
2578 | |
2579 | |
2580 | |
2581 /****************************************************************** | |
2582 ** HTTP CLIENT | |
2583 ******************************************************************/ | |
2584 | |
2585 #if HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 | |
2586 class HttpClient::RequestBodyWrapper : public boost::noncopyable | |
2587 { | |
2588 private: | |
2589 static RequestBodyWrapper& GetObject(void* body) | |
2590 { | |
2591 assert(body != NULL); | |
2592 return *reinterpret_cast<RequestBodyWrapper*>(body); | |
2593 } | |
2594 | |
2595 IRequestBody& body_; | |
2596 bool done_; | |
2597 std::string chunk_; | |
2598 | |
2599 public: | |
2600 RequestBodyWrapper(IRequestBody& body) : | |
2601 body_(body), | |
2602 done_(false) | |
2603 { | |
2604 } | |
2605 | |
2606 static uint8_t IsDone(void* body) | |
2607 { | |
2608 return GetObject(body).done_; | |
2609 } | |
2610 | |
2611 static const void* GetChunkData(void* body) | |
2612 { | |
2613 return GetObject(body).chunk_.c_str(); | |
2614 } | |
2615 | |
2616 static uint32_t GetChunkSize(void* body) | |
2617 { | |
2618 return static_cast<uint32_t>(GetObject(body).chunk_.size()); | |
2619 } | |
2620 | |
2621 static OrthancPluginErrorCode Next(void* body) | |
2622 { | |
2623 RequestBodyWrapper& that = GetObject(body); | |
2624 | |
2625 if (that.done_) | |
2626 { | |
2627 return OrthancPluginErrorCode_BadSequenceOfCalls; | |
2628 } | |
2629 else | |
2630 { | |
2631 try | |
2632 { | |
2633 that.done_ = !that.body_.ReadNextChunk(that.chunk_); | |
2634 return OrthancPluginErrorCode_Success; | |
2635 } | |
2636 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2637 { | |
2638 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2639 } | |
2640 catch (...) | |
2641 { | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2642 return OrthancPluginErrorCode_Plugin; |
22 | 2643 } |
2644 } | |
2645 } | |
2646 }; | |
2647 | |
2648 | |
2649 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
2650 static OrthancPluginErrorCode AnswerAddHeaderCallback(void* answer, | |
2651 const char* key, | |
2652 const char* value) | |
2653 { | |
2654 assert(answer != NULL && key != NULL && value != NULL); | |
2655 | |
2656 try | |
2657 { | |
2658 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddHeader(key, value); | |
2659 return OrthancPluginErrorCode_Success; | |
2660 } | |
2661 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2662 { | |
2663 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2664 } | |
2665 catch (...) | |
2666 { | |
2667 return OrthancPluginErrorCode_Plugin; | |
2668 } | |
2669 } | |
2670 #endif | |
2671 | |
2672 | |
2673 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
2674 static OrthancPluginErrorCode AnswerAddChunkCallback(void* answer, | |
2675 const void* data, | |
2676 uint32_t size) | |
2677 { | |
2678 assert(answer != NULL); | |
2679 | |
2680 try | |
2681 { | |
2682 reinterpret_cast<HttpClient::IAnswer*>(answer)->AddChunk(data, size); | |
2683 return OrthancPluginErrorCode_Success; | |
2684 } | |
2685 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
2686 { | |
2687 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2688 } | |
2689 catch (...) | |
2690 { | |
2691 return OrthancPluginErrorCode_Plugin; | |
2692 } | |
2693 } | |
2694 #endif | |
2695 | |
2696 | |
2697 HttpClient::HttpClient() : | |
2698 httpStatus_(0), | |
2699 method_(OrthancPluginHttpMethod_Get), | |
2700 timeout_(0), | |
2701 pkcs11_(false), | |
2702 chunkedBody_(NULL), | |
2703 allowChunkedTransfers_(true) | |
2704 { | |
2705 } | |
2706 | |
2707 | |
2708 void HttpClient::AddHeaders(const HttpHeaders& headers) | |
2709 { | |
2710 for (HttpHeaders::const_iterator it = headers.begin(); | |
2711 it != headers.end(); ++it) | |
2712 { | |
2713 headers_[it->first] = it->second; | |
2714 } | |
2715 } | |
2716 | |
2717 | |
2718 void HttpClient::SetCredentials(const std::string& username, | |
2719 const std::string& password) | |
2720 { | |
2721 username_ = username; | |
2722 password_ = password; | |
2723 } | |
2724 | |
2725 | |
2726 void HttpClient::ClearCredentials() | |
2727 { | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2728 username_.clear(); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
2729 password_.clear(); |
22 | 2730 } |
2731 | |
2732 | |
2733 void HttpClient::SetCertificate(const std::string& certificateFile, | |
2734 const std::string& keyFile, | |
2735 const std::string& keyPassword) | |
2736 { | |
2737 certificateFile_ = certificateFile; | |
2738 certificateKeyFile_ = keyFile; | |
2739 certificateKeyPassword_ = keyPassword; | |
2740 } | |
2741 | |
2742 | |
2743 void HttpClient::ClearCertificate() | |
2744 { | |
2745 certificateFile_.clear(); | |
2746 certificateKeyFile_.clear(); | |
2747 certificateKeyPassword_.clear(); | |
2748 } | |
2749 | |
2750 | |
2751 void HttpClient::ClearBody() | |
2752 { | |
2753 fullBody_.clear(); | |
2754 chunkedBody_ = NULL; | |
2755 } | |
2756 | |
2757 | |
2758 void HttpClient::SwapBody(std::string& body) | |
2759 { | |
2760 fullBody_.swap(body); | |
2761 chunkedBody_ = NULL; | |
2762 } | |
2763 | |
2764 | |
2765 void HttpClient::SetBody(const std::string& body) | |
2766 { | |
2767 fullBody_ = body; | |
2768 chunkedBody_ = NULL; | |
2769 } | |
2770 | |
2771 | |
2772 void HttpClient::SetBody(IRequestBody& body) | |
2773 { | |
2774 fullBody_.clear(); | |
2775 chunkedBody_ = &body; | |
2776 } | |
2777 | |
2778 | |
2779 namespace | |
2780 { | |
2781 class HeadersWrapper : public boost::noncopyable | |
2782 { | |
2783 private: | |
2784 std::vector<const char*> headersKeys_; | |
2785 std::vector<const char*> headersValues_; | |
2786 | |
2787 public: | |
2788 HeadersWrapper(const HttpClient::HttpHeaders& headers) | |
2789 { | |
2790 headersKeys_.reserve(headers.size()); | |
2791 headersValues_.reserve(headers.size()); | |
2792 | |
2793 for (HttpClient::HttpHeaders::const_iterator it = headers.begin(); it != headers.end(); ++it) | |
2794 { | |
2795 headersKeys_.push_back(it->first.c_str()); | |
2796 headersValues_.push_back(it->second.c_str()); | |
2797 } | |
2798 } | |
2799 | |
2800 void AddStaticString(const char* key, | |
2801 const char* value) | |
2802 { | |
2803 headersKeys_.push_back(key); | |
2804 headersValues_.push_back(value); | |
2805 } | |
2806 | |
2807 uint32_t GetCount() const | |
2808 { | |
2809 return headersKeys_.size(); | |
2810 } | |
2811 | |
2812 const char* const* GetKeys() const | |
2813 { | |
2814 return headersKeys_.empty() ? NULL : &headersKeys_[0]; | |
2815 } | |
2816 | |
2817 const char* const* GetValues() const | |
2818 { | |
2819 return headersValues_.empty() ? NULL : &headersValues_[0]; | |
2820 } | |
2821 }; | |
2822 | |
2823 | |
2824 class MemoryRequestBody : public HttpClient::IRequestBody | |
2825 { | |
2826 private: | |
2827 std::string body_; | |
2828 bool done_; | |
2829 | |
2830 public: | |
2831 MemoryRequestBody(const std::string& body) : | |
2832 body_(body), | |
2833 done_(false) | |
2834 { | |
2835 if (body_.empty()) | |
2836 { | |
2837 done_ = true; | |
2838 } | |
2839 } | |
2840 | |
2841 virtual bool ReadNextChunk(std::string& chunk) | |
2842 { | |
2843 if (done_) | |
2844 { | |
2845 return false; | |
2846 } | |
2847 else | |
2848 { | |
2849 chunk.swap(body_); | |
2850 done_ = true; | |
2851 return true; | |
2852 } | |
2853 } | |
2854 }; | |
2855 | |
2856 | |
2857 // This class mimics Orthanc::ChunkedBuffer | |
2858 class ChunkedBuffer : public boost::noncopyable | |
2859 { | |
2860 private: | |
2861 typedef std::list<std::string*> Content; | |
2862 | |
2863 Content content_; | |
2864 size_t size_; | |
2865 | |
2866 public: | |
2867 ChunkedBuffer() : | |
2868 size_(0) | |
2869 { | |
2870 } | |
2871 | |
2872 ~ChunkedBuffer() | |
2873 { | |
2874 Clear(); | |
2875 } | |
2876 | |
2877 void Clear() | |
2878 { | |
2879 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) | |
2880 { | |
2881 assert(*it != NULL); | |
2882 delete *it; | |
2883 } | |
2884 | |
35 | 2885 size_ = 0; |
22 | 2886 content_.clear(); |
2887 } | |
2888 | |
35 | 2889 /** |
2890 * Since Orthanc 1.9.3, this function also clears the content of | |
2891 * the ChunkedBuffer in order to mimic the behavior of the | |
2892 * original class "Orthanc::ChunkedBuffer". This prevents the | |
2893 * forgetting of calling "Clear()" in order to reduce memory | |
2894 * consumption. | |
2895 **/ | |
2896 void Flatten(std::string& target) | |
22 | 2897 { |
2898 target.resize(size_); | |
2899 | |
2900 size_t pos = 0; | |
2901 | |
2902 for (Content::const_iterator it = content_.begin(); it != content_.end(); ++it) | |
2903 { | |
2904 assert(*it != NULL); | |
2905 size_t s = (*it)->size(); | |
2906 | |
2907 if (s != 0) | |
2908 { | |
2909 memcpy(&target[pos], (*it)->c_str(), s); | |
2910 pos += s; | |
2911 } | |
35 | 2912 |
2913 delete *it; | |
22 | 2914 } |
2915 | |
35 | 2916 assert(pos == target.size()); |
2917 | |
2918 size_ = 0; | |
2919 content_.clear(); | |
22 | 2920 } |
2921 | |
2922 void AddChunk(const void* data, | |
2923 size_t size) | |
2924 { | |
2925 content_.push_back(new std::string(reinterpret_cast<const char*>(data), size)); | |
2926 size_ += size; | |
2927 } | |
2928 | |
2929 void AddChunk(const std::string& chunk) | |
2930 { | |
2931 content_.push_back(new std::string(chunk)); | |
2932 size_ += chunk.size(); | |
2933 } | |
2934 }; | |
2935 | |
2936 | |
2937 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
2938 class MemoryAnswer : public HttpClient::IAnswer | |
2939 { | |
2940 private: | |
2941 HttpClient::HttpHeaders headers_; | |
2942 ChunkedBuffer body_; | |
2943 | |
2944 public: | |
2945 const HttpClient::HttpHeaders& GetHeaders() const | |
2946 { | |
2947 return headers_; | |
2948 } | |
2949 | |
35 | 2950 ChunkedBuffer& GetBody() |
22 | 2951 { |
2952 return body_; | |
2953 } | |
2954 | |
2955 virtual void AddHeader(const std::string& key, | |
2956 const std::string& value) | |
2957 { | |
2958 headers_[key] = value; | |
2959 } | |
2960 | |
2961 virtual void AddChunk(const void* data, | |
2962 size_t size) | |
2963 { | |
2964 body_.AddChunk(data, size); | |
2965 } | |
2966 }; | |
2967 #endif | |
2968 } | |
2969 | |
2970 | |
2971 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
2972 void HttpClient::ExecuteWithStream(uint16_t& httpStatus, | |
2973 IAnswer& answer, | |
2974 IRequestBody& body) const | |
2975 { | |
2976 HeadersWrapper h(headers_); | |
2977 | |
2978 if (method_ == OrthancPluginHttpMethod_Post || | |
2979 method_ == OrthancPluginHttpMethod_Put) | |
2980 { | |
2981 // Automatically set the "Transfer-Encoding" header if absent | |
2982 bool found = false; | |
2983 | |
2984 for (HttpHeaders::const_iterator it = headers_.begin(); it != headers_.end(); ++it) | |
2985 { | |
2986 if (boost::iequals(it->first, "Transfer-Encoding")) | |
2987 { | |
2988 found = true; | |
2989 break; | |
2990 } | |
2991 } | |
2992 | |
2993 if (!found) | |
2994 { | |
2995 h.AddStaticString("Transfer-Encoding", "chunked"); | |
2996 } | |
2997 } | |
2998 | |
2999 RequestBodyWrapper request(body); | |
3000 | |
3001 OrthancPluginErrorCode error = OrthancPluginChunkedHttpClient( | |
3002 GetGlobalContext(), | |
3003 &answer, | |
3004 AnswerAddChunkCallback, | |
3005 AnswerAddHeaderCallback, | |
3006 &httpStatus, | |
3007 method_, | |
3008 url_.c_str(), | |
3009 h.GetCount(), | |
3010 h.GetKeys(), | |
3011 h.GetValues(), | |
3012 &request, | |
3013 RequestBodyWrapper::IsDone, | |
3014 RequestBodyWrapper::GetChunkData, | |
3015 RequestBodyWrapper::GetChunkSize, | |
3016 RequestBodyWrapper::Next, | |
3017 username_.empty() ? NULL : username_.c_str(), | |
3018 password_.empty() ? NULL : password_.c_str(), | |
3019 timeout_, | |
3020 certificateFile_.empty() ? NULL : certificateFile_.c_str(), | |
3021 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), | |
3022 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), | |
3023 pkcs11_ ? 1 : 0); | |
3024 | |
3025 if (error != OrthancPluginErrorCode_Success) | |
3026 { | |
3027 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
3028 } | |
3029 } | |
3030 #endif | |
3031 | |
3032 | |
3033 void HttpClient::ExecuteWithoutStream(uint16_t& httpStatus, | |
3034 HttpHeaders& answerHeaders, | |
3035 std::string& answerBody, | |
3036 const std::string& body) const | |
3037 { | |
3038 HeadersWrapper headers(headers_); | |
3039 | |
3040 MemoryBuffer answerBodyBuffer, answerHeadersBuffer; | |
3041 | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3042 if (body.size() > 0xffffffffu) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3043 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3044 LogError("Cannot handle body size > 4GB"); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3045 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3046 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3047 |
22 | 3048 OrthancPluginErrorCode error = OrthancPluginHttpClient( |
3049 GetGlobalContext(), | |
3050 *answerBodyBuffer, | |
3051 *answerHeadersBuffer, | |
3052 &httpStatus, | |
3053 method_, | |
3054 url_.c_str(), | |
3055 headers.GetCount(), | |
3056 headers.GetKeys(), | |
3057 headers.GetValues(), | |
3058 body.empty() ? NULL : body.c_str(), | |
3059 body.size(), | |
3060 username_.empty() ? NULL : username_.c_str(), | |
3061 password_.empty() ? NULL : password_.c_str(), | |
3062 timeout_, | |
3063 certificateFile_.empty() ? NULL : certificateFile_.c_str(), | |
3064 certificateFile_.empty() ? NULL : certificateKeyFile_.c_str(), | |
3065 certificateFile_.empty() ? NULL : certificateKeyPassword_.c_str(), | |
3066 pkcs11_ ? 1 : 0); | |
3067 | |
3068 if (error != OrthancPluginErrorCode_Success) | |
3069 { | |
3070 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(error); | |
3071 } | |
3072 | |
3073 Json::Value v; | |
3074 answerHeadersBuffer.ToJson(v); | |
3075 | |
3076 if (v.type() != Json::objectValue) | |
3077 { | |
3078 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
3079 } | |
3080 | |
3081 Json::Value::Members members = v.getMemberNames(); | |
3082 answerHeaders.clear(); | |
3083 | |
3084 for (size_t i = 0; i < members.size(); i++) | |
3085 { | |
3086 const Json::Value& h = v[members[i]]; | |
3087 if (h.type() != Json::stringValue) | |
3088 { | |
3089 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
3090 } | |
3091 else | |
3092 { | |
3093 answerHeaders[members[i]] = h.asString(); | |
3094 } | |
3095 } | |
3096 | |
3097 answerBodyBuffer.ToString(answerBody); | |
3098 } | |
3099 | |
3100 | |
3101 void HttpClient::Execute(IAnswer& answer) | |
3102 { | |
3103 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
3104 if (allowChunkedTransfers_) | |
3105 { | |
3106 if (chunkedBody_ != NULL) | |
3107 { | |
3108 ExecuteWithStream(httpStatus_, answer, *chunkedBody_); | |
3109 } | |
3110 else | |
3111 { | |
3112 MemoryRequestBody wrapper(fullBody_); | |
3113 ExecuteWithStream(httpStatus_, answer, wrapper); | |
3114 } | |
3115 | |
3116 return; | |
3117 } | |
3118 #endif | |
3119 | |
3120 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked | |
3121 // transfers are disabled. This results in higher memory usage | |
3122 // (all chunks from the answer body are sent at once) | |
3123 | |
3124 HttpHeaders answerHeaders; | |
3125 std::string answerBody; | |
3126 Execute(answerHeaders, answerBody); | |
3127 | |
3128 for (HttpHeaders::const_iterator it = answerHeaders.begin(); | |
3129 it != answerHeaders.end(); ++it) | |
3130 { | |
3131 answer.AddHeader(it->first, it->second); | |
3132 } | |
3133 | |
3134 if (!answerBody.empty()) | |
3135 { | |
3136 answer.AddChunk(answerBody.c_str(), answerBody.size()); | |
3137 } | |
3138 } | |
3139 | |
3140 | |
3141 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, | |
3142 std::string& answerBody /* out */) | |
3143 { | |
3144 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_CLIENT == 1 | |
3145 if (allowChunkedTransfers_) | |
3146 { | |
3147 MemoryAnswer answer; | |
3148 Execute(answer); | |
3149 answerHeaders = answer.GetHeaders(); | |
3150 answer.GetBody().Flatten(answerBody); | |
3151 return; | |
3152 } | |
3153 #endif | |
3154 | |
3155 // Compatibility mode for Orthanc SDK <= 1.5.6 or if chunked | |
3156 // transfers are disabled. This results in higher memory usage | |
3157 // (all chunks from the request body are sent at once) | |
3158 | |
3159 if (chunkedBody_ != NULL) | |
3160 { | |
3161 ChunkedBuffer buffer; | |
3162 | |
3163 std::string chunk; | |
3164 while (chunkedBody_->ReadNextChunk(chunk)) | |
3165 { | |
3166 buffer.AddChunk(chunk); | |
3167 } | |
3168 | |
3169 std::string body; | |
3170 buffer.Flatten(body); | |
3171 | |
3172 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, body); | |
3173 } | |
3174 else | |
3175 { | |
3176 ExecuteWithoutStream(httpStatus_, answerHeaders, answerBody, fullBody_); | |
3177 } | |
3178 } | |
3179 | |
3180 | |
3181 void HttpClient::Execute(HttpHeaders& answerHeaders /* out */, | |
3182 Json::Value& answerBody /* out */) | |
3183 { | |
3184 std::string body; | |
3185 Execute(answerHeaders, body); | |
3186 | |
31
cfeda58d0c8e
remove calls to deprecated classes of JsonCpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
3187 if (!ReadJson(answerBody, body)) |
22 | 3188 { |
3189 LogError("Cannot convert HTTP answer body to JSON"); | |
3190 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
3191 } | |
3192 } | |
3193 | |
3194 | |
3195 void HttpClient::Execute() | |
3196 { | |
3197 HttpHeaders answerHeaders; | |
3198 std::string body; | |
3199 Execute(answerHeaders, body); | |
3200 } | |
3201 | |
3202 #endif /* HAS_ORTHANC_PLUGIN_HTTP_CLIENT == 1 */ | |
3203 | |
3204 | |
3205 | |
3206 | |
3207 | |
3208 /****************************************************************** | |
3209 ** CHUNKED HTTP SERVER | |
3210 ******************************************************************/ | |
3211 | |
3212 namespace Internals | |
3213 { | |
3214 void NullRestCallback(OrthancPluginRestOutput* output, | |
3215 const char* url, | |
3216 const OrthancPluginHttpRequest* request) | |
3217 { | |
3218 } | |
3219 | |
3220 IChunkedRequestReader *NullChunkedRestCallback(const char* url, | |
3221 const OrthancPluginHttpRequest* request) | |
3222 { | |
3223 return NULL; | |
3224 } | |
3225 | |
3226 | |
3227 #if HAS_ORTHANC_PLUGIN_CHUNKED_HTTP_SERVER == 1 | |
3228 | |
3229 OrthancPluginErrorCode ChunkedRequestReaderAddChunk( | |
3230 OrthancPluginServerChunkedRequestReader* reader, | |
3231 const void* data, | |
3232 uint32_t size) | |
3233 { | |
3234 try | |
3235 { | |
3236 if (reader == NULL) | |
3237 { | |
3238 return OrthancPluginErrorCode_InternalError; | |
3239 } | |
3240 | |
3241 reinterpret_cast<IChunkedRequestReader*>(reader)->AddChunk(data, size); | |
3242 return OrthancPluginErrorCode_Success; | |
3243 } | |
3244 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3245 { | |
3246 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3247 } | |
3248 catch (boost::bad_lexical_cast&) | |
3249 { | |
3250 return OrthancPluginErrorCode_BadFileFormat; | |
3251 } | |
3252 catch (...) | |
3253 { | |
3254 return OrthancPluginErrorCode_Plugin; | |
3255 } | |
3256 } | |
3257 | |
3258 | |
3259 OrthancPluginErrorCode ChunkedRequestReaderExecute( | |
3260 OrthancPluginServerChunkedRequestReader* reader, | |
3261 OrthancPluginRestOutput* output) | |
3262 { | |
3263 try | |
3264 { | |
3265 if (reader == NULL) | |
3266 { | |
3267 return OrthancPluginErrorCode_InternalError; | |
3268 } | |
3269 | |
3270 reinterpret_cast<IChunkedRequestReader*>(reader)->Execute(output); | |
3271 return OrthancPluginErrorCode_Success; | |
3272 } | |
3273 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3274 { | |
3275 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3276 } | |
3277 catch (boost::bad_lexical_cast&) | |
3278 { | |
3279 return OrthancPluginErrorCode_BadFileFormat; | |
3280 } | |
3281 catch (...) | |
3282 { | |
3283 return OrthancPluginErrorCode_Plugin; | |
3284 } | |
3285 } | |
3286 | |
3287 | |
3288 void ChunkedRequestReaderFinalize( | |
3289 OrthancPluginServerChunkedRequestReader* reader) | |
3290 { | |
3291 if (reader != NULL) | |
3292 { | |
3293 delete reinterpret_cast<IChunkedRequestReader*>(reader); | |
3294 } | |
3295 } | |
3296 | |
3297 #else | |
3298 | |
3299 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, | |
3300 const char* url, | |
3301 const OrthancPluginHttpRequest* request, | |
3302 RestCallback GetHandler, | |
3303 ChunkedRestCallback PostHandler, | |
3304 RestCallback DeleteHandler, | |
3305 ChunkedRestCallback PutHandler) | |
3306 { | |
3307 try | |
3308 { | |
3309 std::string allowed; | |
3310 | |
3311 if (GetHandler != Internals::NullRestCallback) | |
3312 { | |
3313 allowed += "GET"; | |
3314 } | |
3315 | |
3316 if (PostHandler != Internals::NullChunkedRestCallback) | |
3317 { | |
3318 if (!allowed.empty()) | |
3319 { | |
3320 allowed += ","; | |
3321 } | |
3322 | |
3323 allowed += "POST"; | |
3324 } | |
3325 | |
3326 if (DeleteHandler != Internals::NullRestCallback) | |
3327 { | |
3328 if (!allowed.empty()) | |
3329 { | |
3330 allowed += ","; | |
3331 } | |
3332 | |
3333 allowed += "DELETE"; | |
3334 } | |
3335 | |
3336 if (PutHandler != Internals::NullChunkedRestCallback) | |
3337 { | |
3338 if (!allowed.empty()) | |
3339 { | |
3340 allowed += ","; | |
3341 } | |
3342 | |
3343 allowed += "PUT"; | |
3344 } | |
3345 | |
3346 switch (request->method) | |
3347 { | |
3348 case OrthancPluginHttpMethod_Get: | |
3349 if (GetHandler == Internals::NullRestCallback) | |
3350 { | |
3351 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
3352 } | |
3353 else | |
3354 { | |
3355 GetHandler(output, url, request); | |
3356 } | |
3357 | |
3358 break; | |
3359 | |
3360 case OrthancPluginHttpMethod_Post: | |
3361 if (PostHandler == Internals::NullChunkedRestCallback) | |
3362 { | |
3363 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
3364 } | |
3365 else | |
3366 { | |
3367 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); | |
3368 if (reader.get() == NULL) | |
3369 { | |
3370 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3371 } | |
3372 else | |
3373 { | |
3374 reader->AddChunk(request->body, request->bodySize); | |
3375 reader->Execute(output); | |
3376 } | |
3377 } | |
3378 | |
3379 break; | |
3380 | |
3381 case OrthancPluginHttpMethod_Delete: | |
3382 if (DeleteHandler == Internals::NullRestCallback) | |
3383 { | |
3384 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
3385 } | |
3386 else | |
3387 { | |
3388 DeleteHandler(output, url, request); | |
3389 } | |
3390 | |
3391 break; | |
3392 | |
3393 case OrthancPluginHttpMethod_Put: | |
3394 if (PutHandler == Internals::NullChunkedRestCallback) | |
3395 { | |
3396 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
3397 } | |
3398 else | |
3399 { | |
3400 boost::movelib::unique_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); | |
3401 if (reader.get() == NULL) | |
3402 { | |
3403 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3404 } | |
3405 else | |
3406 { | |
3407 reader->AddChunk(request->body, request->bodySize); | |
3408 reader->Execute(output); | |
3409 } | |
3410 } | |
3411 | |
3412 break; | |
3413 | |
3414 default: | |
3415 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
3416 } | |
3417 | |
3418 return OrthancPluginErrorCode_Success; | |
3419 } | |
3420 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3421 { | |
3422 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 | |
3423 if (HasGlobalContext() && | |
3424 e.HasDetails()) | |
3425 { | |
3426 // The "false" instructs Orthanc not to log the detailed | |
3427 // error message. This is to avoid duplicating the details, | |
3428 // because "OrthancException" already does it on construction. | |
3429 OrthancPluginSetHttpErrorDetails | |
3430 (GetGlobalContext(), output, e.GetDetails(), false); | |
3431 } | |
3432 #endif | |
3433 | |
3434 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3435 } | |
3436 catch (boost::bad_lexical_cast&) | |
3437 { | |
3438 return OrthancPluginErrorCode_BadFileFormat; | |
3439 } | |
3440 catch (...) | |
3441 { | |
3442 return OrthancPluginErrorCode_Plugin; | |
3443 } | |
3444 } | |
3445 #endif | |
3446 } | |
3447 | |
3448 | |
3449 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 | |
3450 OrthancPluginErrorCode IStorageCommitmentScpHandler::Lookup( | |
3451 OrthancPluginStorageCommitmentFailureReason* target, | |
3452 void* rawHandler, | |
3453 const char* sopClassUid, | |
3454 const char* sopInstanceUid) | |
3455 { | |
3456 assert(target != NULL && | |
3457 rawHandler != NULL); | |
3458 | |
3459 try | |
3460 { | |
3461 IStorageCommitmentScpHandler& handler = *reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); | |
3462 *target = handler.Lookup(sopClassUid, sopInstanceUid); | |
3463 return OrthancPluginErrorCode_Success; | |
3464 } | |
3465 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3466 { | |
3467 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3468 } | |
3469 catch (...) | |
3470 { | |
3471 return OrthancPluginErrorCode_Plugin; | |
3472 } | |
3473 } | |
3474 #endif | |
3475 | |
3476 | |
3477 #if HAS_ORTHANC_PLUGIN_STORAGE_COMMITMENT_SCP == 1 | |
3478 void IStorageCommitmentScpHandler::Destructor(void* rawHandler) | |
3479 { | |
3480 assert(rawHandler != NULL); | |
3481 delete reinterpret_cast<IStorageCommitmentScpHandler*>(rawHandler); | |
3482 } | |
3483 #endif | |
3484 | |
3485 | |
3486 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) | |
3487 DicomInstance::DicomInstance(const OrthancPluginDicomInstance* instance) : | |
3488 toFree_(false), | |
3489 instance_(instance) | |
3490 { | |
3491 } | |
3492 #else | |
3493 DicomInstance::DicomInstance(OrthancPluginDicomInstance* instance) : | |
3494 toFree_(false), | |
3495 instance_(instance) | |
3496 { | |
3497 } | |
3498 #endif | |
3499 | |
3500 | |
3501 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3502 DicomInstance::DicomInstance(const void* buffer, | |
3503 size_t size) : | |
3504 toFree_(true), | |
3505 instance_(OrthancPluginCreateDicomInstance(GetGlobalContext(), buffer, size)) | |
3506 { | |
3507 if (instance_ == NULL) | |
3508 { | |
3509 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
3510 } | |
3511 } | |
3512 #endif | |
3513 | |
3514 | |
3515 DicomInstance::~DicomInstance() | |
3516 { | |
3517 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3518 if (toFree_ && | |
3519 instance_ != NULL) | |
3520 { | |
3521 OrthancPluginFreeDicomInstance( | |
3522 GetGlobalContext(), const_cast<OrthancPluginDicomInstance*>(instance_)); | |
3523 } | |
3524 #endif | |
3525 } | |
3526 | |
3527 | |
3528 std::string DicomInstance::GetRemoteAet() const | |
3529 { | |
3530 const char* s = OrthancPluginGetInstanceRemoteAet(GetGlobalContext(), instance_); | |
3531 if (s == NULL) | |
3532 { | |
3533 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3534 } | |
3535 else | |
3536 { | |
3537 return std::string(s); | |
3538 } | |
3539 } | |
3540 | |
3541 | |
3542 void DicomInstance::GetJson(Json::Value& target) const | |
3543 { | |
3544 OrthancString s; | |
3545 s.Assign(OrthancPluginGetInstanceJson(GetGlobalContext(), instance_)); | |
3546 s.ToJson(target); | |
3547 } | |
3548 | |
3549 | |
3550 void DicomInstance::GetSimplifiedJson(Json::Value& target) const | |
3551 { | |
3552 OrthancString s; | |
3553 s.Assign(OrthancPluginGetInstanceSimplifiedJson(GetGlobalContext(), instance_)); | |
3554 s.ToJson(target); | |
3555 } | |
3556 | |
3557 | |
3558 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) | |
3559 std::string DicomInstance::GetTransferSyntaxUid() const | |
3560 { | |
3561 OrthancString s; | |
3562 s.Assign(OrthancPluginGetInstanceTransferSyntaxUid(GetGlobalContext(), instance_)); | |
3563 | |
3564 std::string result; | |
3565 s.ToString(result); | |
3566 return result; | |
3567 } | |
3568 #endif | |
3569 | |
3570 | |
3571 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 6, 1) | |
3572 bool DicomInstance::HasPixelData() const | |
3573 { | |
3574 int32_t result = OrthancPluginHasInstancePixelData(GetGlobalContext(), instance_); | |
3575 if (result < 0) | |
3576 { | |
3577 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3578 } | |
3579 else | |
3580 { | |
3581 return (result != 0); | |
3582 } | |
3583 } | |
3584 #endif | |
3585 | |
3586 | |
3587 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3588 void DicomInstance::GetRawFrame(std::string& target, | |
3589 unsigned int frameIndex) const | |
3590 { | |
3591 MemoryBuffer buffer; | |
3592 OrthancPluginErrorCode code = OrthancPluginGetInstanceRawFrame( | |
3593 GetGlobalContext(), *buffer, instance_, frameIndex); | |
3594 | |
3595 if (code == OrthancPluginErrorCode_Success) | |
3596 { | |
3597 buffer.ToString(target); | |
3598 } | |
3599 else | |
3600 { | |
3601 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
3602 } | |
3603 } | |
3604 #endif | |
3605 | |
3606 | |
3607 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3608 OrthancImage* DicomInstance::GetDecodedFrame(unsigned int frameIndex) const | |
3609 { | |
3610 OrthancPluginImage* image = OrthancPluginGetInstanceDecodedFrame( | |
3611 GetGlobalContext(), instance_, frameIndex); | |
3612 | |
3613 if (image == NULL) | |
3614 { | |
3615 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3616 } | |
3617 else | |
3618 { | |
3619 return new OrthancImage(image); | |
3620 } | |
3621 } | |
3622 #endif | |
3623 | |
3624 | |
3625 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3626 void DicomInstance::Serialize(std::string& target) const | |
3627 { | |
3628 MemoryBuffer buffer; | |
3629 OrthancPluginErrorCode code = OrthancPluginSerializeDicomInstance( | |
3630 GetGlobalContext(), *buffer, instance_); | |
3631 | |
3632 if (code == OrthancPluginErrorCode_Success) | |
3633 { | |
3634 buffer.ToString(target); | |
3635 } | |
3636 else | |
3637 { | |
3638 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
3639 } | |
3640 } | |
3641 #endif | |
3642 | |
3643 | |
3644 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 7, 0) | |
3645 DicomInstance* DicomInstance::Transcode(const void* buffer, | |
3646 size_t size, | |
3647 const std::string& transferSyntax) | |
3648 { | |
3649 OrthancPluginDicomInstance* instance = OrthancPluginTranscodeDicomInstance( | |
3650 GetGlobalContext(), buffer, size, transferSyntax.c_str()); | |
3651 | |
3652 if (instance == NULL) | |
3653 { | |
3654 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
3655 } | |
3656 else | |
3657 { | |
3658 boost::movelib::unique_ptr<DicomInstance> result(new DicomInstance(instance)); | |
3659 result->toFree_ = true; | |
3660 return result.release(); | |
3661 } | |
3662 } | |
3663 #endif | |
40
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3664 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3665 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3666 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3667 static std::vector<std::string> WebDavConvertPath(uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3668 const char* const* pathItems) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3669 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3670 std::vector<std::string> result(pathSize); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3671 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3672 for (uint32_t i = 0; i < pathSize; i++) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3673 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3674 result[i] = pathItems[i]; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3675 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3676 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3677 return result; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3678 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3679 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3680 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3681 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3682 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3683 static OrthancPluginErrorCode WebDavIsExistingFolder(uint8_t* isExisting, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3684 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3685 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3686 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3687 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3688 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3689 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3690 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3691 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3692 *isExisting = (that.IsExistingFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3693 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3694 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3695 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3696 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3697 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3698 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3699 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3700 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3701 return OrthancPluginErrorCode_Plugin; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3702 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3703 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3704 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3705 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3706 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3707 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3708 static OrthancPluginErrorCode WebDavListFolder(uint8_t* isExisting, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3709 OrthancPluginWebDavCollection* collection, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3710 OrthancPluginWebDavAddFile addFile, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3711 OrthancPluginWebDavAddFolder addFolder, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3712 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3713 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3714 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3715 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3716 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3717 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3718 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3719 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3720 std::list<IWebDavCollection::FileInfo> files; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3721 std::list<IWebDavCollection::FolderInfo> subfolders; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3722 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3723 if (!that.ListFolder(files, subfolders, WebDavConvertPath(pathSize, pathItems))) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3724 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3725 *isExisting = 0; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3726 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3727 else |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3728 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3729 *isExisting = 1; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3730 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3731 for (std::list<IWebDavCollection::FileInfo>::const_iterator |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3732 it = files.begin(); it != files.end(); ++it) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3733 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3734 OrthancPluginErrorCode code = addFile( |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3735 collection, it->GetName().c_str(), it->GetContentSize(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3736 it->GetMimeType().c_str(), it->GetDateTime().c_str()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3737 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3738 if (code != OrthancPluginErrorCode_Success) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3739 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3740 return code; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3741 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3742 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3743 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3744 for (std::list<IWebDavCollection::FolderInfo>::const_iterator it = |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3745 subfolders.begin(); it != subfolders.end(); ++it) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3746 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3747 OrthancPluginErrorCode code = addFolder( |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3748 collection, it->GetName().c_str(), it->GetDateTime().c_str()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3749 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3750 if (code != OrthancPluginErrorCode_Success) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3751 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3752 return code; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3753 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3754 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3755 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3756 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3757 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3758 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3759 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3760 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3761 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3762 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3763 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3764 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3765 return OrthancPluginErrorCode_Plugin; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3766 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3767 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3768 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3769 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3770 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3771 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3772 static OrthancPluginErrorCode WebDavRetrieveFile(OrthancPluginWebDavCollection* collection, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3773 OrthancPluginWebDavRetrieveFile retrieveFile, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3774 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3775 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3776 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3777 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3778 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3779 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3780 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3781 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3782 std::string content, mime, dateTime; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3783 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3784 if (that.GetFile(content, mime, dateTime, WebDavConvertPath(pathSize, pathItems))) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3785 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3786 return retrieveFile(collection, content.empty() ? NULL : content.c_str(), |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3787 content.size(), mime.c_str(), dateTime.c_str()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3788 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3789 else |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3790 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3791 // Inexisting file |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3792 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3793 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3794 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3795 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3796 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3797 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3798 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3799 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3800 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3801 return OrthancPluginErrorCode_InternalError; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3802 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3803 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3804 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3805 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3806 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3807 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3808 static OrthancPluginErrorCode WebDavStoreFileCallback(uint8_t* isReadOnly, /* out */ |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3809 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3810 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3811 const void* data, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3812 uint64_t size, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3813 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3814 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3815 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3816 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3817 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3818 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3819 if (static_cast<uint64_t>(static_cast<size_t>(size)) != size) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3820 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3821 ORTHANC_PLUGINS_THROW_EXCEPTION(NotEnoughMemory); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3822 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3823 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3824 *isReadOnly = (that.StoreFile(WebDavConvertPath(pathSize, pathItems), data, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3825 static_cast<size_t>(size)) ? 1 : 0); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3826 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3827 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3828 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3829 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3830 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3831 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3832 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3833 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3834 return OrthancPluginErrorCode_InternalError; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3835 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3836 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3837 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3838 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3839 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3840 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3841 static OrthancPluginErrorCode WebDavCreateFolderCallback(uint8_t* isReadOnly, /* out */ |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3842 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3843 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3844 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3845 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3846 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3847 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3848 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3849 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3850 *isReadOnly = (that.CreateFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3851 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3852 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3853 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3854 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3855 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3856 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3857 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3858 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3859 return OrthancPluginErrorCode_InternalError; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3860 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3861 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3862 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3863 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3864 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3865 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3866 static OrthancPluginErrorCode WebDavDeleteItemCallback(uint8_t* isReadOnly, /* out */ |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3867 uint32_t pathSize, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3868 const char* const* pathItems, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3869 void* payload) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3870 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3871 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3872 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3873 try |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3874 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3875 *isReadOnly = (that.DeleteItem(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3876 return OrthancPluginErrorCode_Success; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3877 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3878 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3879 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3880 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3881 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3882 catch (...) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3883 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3884 return OrthancPluginErrorCode_InternalError; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3885 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3886 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3887 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3888 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3889 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3890 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3891 void IWebDavCollection::Register(const std::string& uri, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3892 IWebDavCollection& collection) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3893 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3894 OrthancPluginErrorCode code = OrthancPluginRegisterWebDavCollection( |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3895 GetGlobalContext(), uri.c_str(), WebDavIsExistingFolder, WebDavListFolder, WebDavRetrieveFile, |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3896 WebDavStoreFileCallback, WebDavCreateFolderCallback, WebDavDeleteItemCallback, &collection); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3897 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3898 if (code != OrthancPluginErrorCode_Success) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3899 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3900 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3901 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3902 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3903 #endif |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3904 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3905 void GetHttpHeaders(std::map<std::string, std::string>& result, const OrthancPluginHttpRequest* request) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3906 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3907 result.clear(); |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3908 |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3909 for (uint32_t i = 0; i < request->headersCount; ++i) |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3910 { |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3911 result[request->headersKeys[i]] = request->headersValues[i]; |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3912 } |
1256194e1c08
sync orthanc + sdk 1.5.0 + added more info in error logs
Alain Mazy <am@osimis.io>
parents:
35
diff
changeset
|
3913 } |
22 | 3914 } |