annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3528:f6fe095f7130

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