annotate Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3394:2f82ef41bf5a

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