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