annotate Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 73:0a18367a3358 OrthancTransfers-1.5

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