comparison Resources/Orthanc/Sdk-1.10.0/orthanc/OrthancCPlugin.h @ 0:3ecef5782f2c

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Oct 2023 17:59:44 +0200
parents
children 7f821a89e000
comparison
equal deleted inserted replaced
-1:000000000000 0:3ecef5782f2c
1 /**
2 * \mainpage
3 *
4 * This C/C++ SDK allows external developers to create plugins that
5 * can be loaded into Orthanc to extend its functionality. Each
6 * Orthanc plugin must expose 4 public functions with the following
7 * signatures:
8 *
9 * -# <tt>int32_t OrthancPluginInitialize(const OrthancPluginContext* context)</tt>:
10 * This function is invoked by Orthanc when it loads the plugin on startup.
11 * The plugin must:
12 * - Check its compatibility with the Orthanc version using
13 * ::OrthancPluginCheckVersion().
14 * - Store the context pointer so that it can use the plugin
15 * services of Orthanc.
16 * - Register all its REST callbacks using ::OrthancPluginRegisterRestCallback().
17 * - Possibly register its callback for received DICOM instances using ::OrthancPluginRegisterOnStoredInstanceCallback().
18 * - Possibly register its callback for changes to the DICOM store using ::OrthancPluginRegisterOnChangeCallback().
19 * - Possibly register a custom storage area using ::OrthancPluginRegisterStorageArea2().
20 * - Possibly register a custom database back-end area using OrthancPluginRegisterDatabaseBackendV3().
21 * - Possibly register a handler for C-Find SCP using OrthancPluginRegisterFindCallback().
22 * - Possibly register a handler for C-Find SCP against DICOM worklists using OrthancPluginRegisterWorklistCallback().
23 * - Possibly register a handler for C-Move SCP using OrthancPluginRegisterMoveCallback().
24 * - Possibly register a custom decoder for DICOM images using OrthancPluginRegisterDecodeImageCallback().
25 * - Possibly register a callback to filter incoming HTTP requests using OrthancPluginRegisterIncomingHttpRequestFilter2().
26 * - Possibly register a callback to unserialize jobs using OrthancPluginRegisterJobsUnserializer().
27 * - Possibly register a callback to refresh its metrics using OrthancPluginRegisterRefreshMetricsCallback().
28 * - Possibly register a callback to answer chunked HTTP transfers using ::OrthancPluginRegisterChunkedRestCallback().
29 * - Possibly register a callback for Storage Commitment SCP using ::OrthancPluginRegisterStorageCommitmentScpCallback().
30 * - Possibly register a callback to keep/discard/modify incoming DICOM instances using OrthancPluginRegisterReceivedInstanceCallback().
31 * - Possibly register a custom transcoder for DICOM images using OrthancPluginRegisterTranscoderCallback().
32 * - Possibly register a callback to discard instances received through DICOM C-STORE using OrthancPluginRegisterIncomingCStoreInstanceFilter().
33 * -# <tt>void OrthancPluginFinalize()</tt>:
34 * This function is invoked by Orthanc during its shutdown. The plugin
35 * must free all its memory.
36 * -# <tt>const char* OrthancPluginGetName()</tt>:
37 * The plugin must return a short string to identify itself.
38 * -# <tt>const char* OrthancPluginGetVersion()</tt>:
39 * The plugin must return a string containing its version number.
40 *
41 * The name and the version of a plugin is only used to prevent it
42 * from being loaded twice. Note that, in C++, it is mandatory to
43 * declare these functions within an <tt>extern "C"</tt> section.
44 *
45 * To ensure multi-threading safety, the various REST callbacks are
46 * guaranteed to be executed in mutual exclusion since Orthanc
47 * 0.8.5. If this feature is undesired (notably when developing
48 * high-performance plugins handling simultaneous requests), use
49 * ::OrthancPluginRegisterRestCallbackNoLock().
50 **/
51
52
53
54 /**
55 * @defgroup Images Images and compression
56 * @brief Functions to deal with images and compressed buffers.
57 *
58 * @defgroup REST REST
59 * @brief Functions to answer REST requests in a callback.
60 *
61 * @defgroup Callbacks Callbacks
62 * @brief Functions to register and manage callbacks by the plugins.
63 *
64 * @defgroup DicomCallbacks DicomCallbacks
65 * @brief Functions to register and manage DICOM callbacks (worklists, C-FIND, C-MOVE, storage commitment).
66 *
67 * @defgroup Orthanc Orthanc
68 * @brief Functions to access the content of the Orthanc server.
69 *
70 * @defgroup DicomInstance DicomInstance
71 * @brief Functions to access DICOM images that are managed by the Orthanc core.
72 **/
73
74
75
76 /**
77 * @defgroup Toolbox Toolbox
78 * @brief Generic functions to help with the creation of plugins.
79 **/
80
81
82
83 /**
84 * Orthanc - A Lightweight, RESTful DICOM Store
85 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
86 * Department, University Hospital of Liege, Belgium
87 * Copyright (C) 2017-2022 Osimis S.A., Belgium
88 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
89 *
90 * This program is free software: you can redistribute it and/or
91 * modify it under the terms of the GNU General Public License as
92 * published by the Free Software Foundation, either version 3 of the
93 * License, or (at your option) any later version.
94 *
95 * This program is distributed in the hope that it will be useful, but
96 * WITHOUT ANY WARRANTY; without even the implied warranty of
97 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98 * General Public License for more details.
99 *
100 * You should have received a copy of the GNU General Public License
101 * along with this program. If not, see <http://www.gnu.org/licenses/>.
102 **/
103
104
105
106 #pragma once
107
108
109 #include <stdio.h>
110 #include <string.h>
111
112 #ifdef WIN32
113 # define ORTHANC_PLUGINS_API __declspec(dllexport)
114 #elif __GNUC__ >= 4
115 # define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default")))
116 #else
117 # define ORTHANC_PLUGINS_API
118 #endif
119
120 #define ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER 1
121 #define ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER 10
122 #define ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER 0
123
124
125 #if !defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)
126 #define ORTHANC_PLUGINS_VERSION_IS_ABOVE(major, minor, revision) \
127 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER > major || \
128 (ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER == major && \
129 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER > minor || \
130 (ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER == minor && \
131 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER >= revision))))
132 #endif
133
134
135
136 /********************************************************************
137 ** Check that function inlining is properly supported. The use of
138 ** inlining is required, to avoid the duplication of object code
139 ** between two compilation modules that would use the Orthanc Plugin
140 ** API.
141 ********************************************************************/
142
143 /* If the auto-detection of the "inline" keyword below does not work
144 automatically and that your compiler is known to properly support
145 inlining, uncomment the following #define and adapt the definition
146 of "static inline". */
147
148 /* #define ORTHANC_PLUGIN_INLINE static inline */
149
150 #ifndef ORTHANC_PLUGIN_INLINE
151 # if __STDC_VERSION__ >= 199901L
152 /* This is C99 or above: http://predef.sourceforge.net/prestd.html */
153 # define ORTHANC_PLUGIN_INLINE static inline
154 # elif defined(__cplusplus)
155 /* This is C++ */
156 # define ORTHANC_PLUGIN_INLINE static inline
157 # elif defined(__GNUC__)
158 /* This is GCC running in C89 mode */
159 # define ORTHANC_PLUGIN_INLINE static __inline
160 # elif defined(_MSC_VER)
161 /* This is Visual Studio running in C89 mode */
162 # define ORTHANC_PLUGIN_INLINE static __inline
163 # else
164 # error Your compiler is not known to support the "inline" keyword
165 # endif
166 #endif
167
168
169
170 /********************************************************************
171 ** Inclusion of standard libraries.
172 ********************************************************************/
173
174 /**
175 * For Microsoft Visual Studio, a compatibility "stdint.h" can be
176 * downloaded at the following URL:
177 * https://hg.orthanc-server.com/orthanc/raw-file/tip/Resources/ThirdParty/VisualStudio/stdint.h
178 **/
179 #include <stdint.h>
180
181 #include <stdlib.h>
182
183
184
185 /********************************************************************
186 ** Definition of the Orthanc Plugin API.
187 ********************************************************************/
188
189 /** @{ */
190
191 #ifdef __cplusplus
192 extern "C"
193 {
194 #endif
195
196 /**
197 * The various error codes that can be returned by the Orthanc core.
198 **/
199 typedef enum
200 {
201 OrthancPluginErrorCode_InternalError = -1 /*!< Internal error */,
202 OrthancPluginErrorCode_Success = 0 /*!< Success */,
203 OrthancPluginErrorCode_Plugin = 1 /*!< Error encountered within the plugin engine */,
204 OrthancPluginErrorCode_NotImplemented = 2 /*!< Not implemented yet */,
205 OrthancPluginErrorCode_ParameterOutOfRange = 3 /*!< Parameter out of range */,
206 OrthancPluginErrorCode_NotEnoughMemory = 4 /*!< The server hosting Orthanc is running out of memory */,
207 OrthancPluginErrorCode_BadParameterType = 5 /*!< Bad type for a parameter */,
208 OrthancPluginErrorCode_BadSequenceOfCalls = 6 /*!< Bad sequence of calls */,
209 OrthancPluginErrorCode_InexistentItem = 7 /*!< Accessing an inexistent item */,
210 OrthancPluginErrorCode_BadRequest = 8 /*!< Bad request */,
211 OrthancPluginErrorCode_NetworkProtocol = 9 /*!< Error in the network protocol */,
212 OrthancPluginErrorCode_SystemCommand = 10 /*!< Error while calling a system command */,
213 OrthancPluginErrorCode_Database = 11 /*!< Error with the database engine */,
214 OrthancPluginErrorCode_UriSyntax = 12 /*!< Badly formatted URI */,
215 OrthancPluginErrorCode_InexistentFile = 13 /*!< Inexistent file */,
216 OrthancPluginErrorCode_CannotWriteFile = 14 /*!< Cannot write to file */,
217 OrthancPluginErrorCode_BadFileFormat = 15 /*!< Bad file format */,
218 OrthancPluginErrorCode_Timeout = 16 /*!< Timeout */,
219 OrthancPluginErrorCode_UnknownResource = 17 /*!< Unknown resource */,
220 OrthancPluginErrorCode_IncompatibleDatabaseVersion = 18 /*!< Incompatible version of the database */,
221 OrthancPluginErrorCode_FullStorage = 19 /*!< The file storage is full */,
222 OrthancPluginErrorCode_CorruptedFile = 20 /*!< Corrupted file (e.g. inconsistent MD5 hash) */,
223 OrthancPluginErrorCode_InexistentTag = 21 /*!< Inexistent tag */,
224 OrthancPluginErrorCode_ReadOnly = 22 /*!< Cannot modify a read-only data structure */,
225 OrthancPluginErrorCode_IncompatibleImageFormat = 23 /*!< Incompatible format of the images */,
226 OrthancPluginErrorCode_IncompatibleImageSize = 24 /*!< Incompatible size of the images */,
227 OrthancPluginErrorCode_SharedLibrary = 25 /*!< Error while using a shared library (plugin) */,
228 OrthancPluginErrorCode_UnknownPluginService = 26 /*!< Plugin invoking an unknown service */,
229 OrthancPluginErrorCode_UnknownDicomTag = 27 /*!< Unknown DICOM tag */,
230 OrthancPluginErrorCode_BadJson = 28 /*!< Cannot parse a JSON document */,
231 OrthancPluginErrorCode_Unauthorized = 29 /*!< Bad credentials were provided to an HTTP request */,
232 OrthancPluginErrorCode_BadFont = 30 /*!< Badly formatted font file */,
233 OrthancPluginErrorCode_DatabasePlugin = 31 /*!< The plugin implementing a custom database back-end does not fulfill the proper interface */,
234 OrthancPluginErrorCode_StorageAreaPlugin = 32 /*!< Error in the plugin implementing a custom storage area */,
235 OrthancPluginErrorCode_EmptyRequest = 33 /*!< The request is empty */,
236 OrthancPluginErrorCode_NotAcceptable = 34 /*!< Cannot send a response which is acceptable according to the Accept HTTP header */,
237 OrthancPluginErrorCode_NullPointer = 35 /*!< Cannot handle a NULL pointer */,
238 OrthancPluginErrorCode_DatabaseUnavailable = 36 /*!< The database is currently not available (probably a transient situation) */,
239 OrthancPluginErrorCode_CanceledJob = 37 /*!< This job was canceled */,
240 OrthancPluginErrorCode_BadGeometry = 38 /*!< Geometry error encountered in Stone */,
241 OrthancPluginErrorCode_SslInitialization = 39 /*!< Cannot initialize SSL encryption, check out your certificates */,
242 OrthancPluginErrorCode_DiscontinuedAbi = 40 /*!< Calling a function that has been removed from the Orthanc Framework */,
243 OrthancPluginErrorCode_BadRange = 41 /*!< Incorrect range request */,
244 OrthancPluginErrorCode_DatabaseCannotSerialize = 42 /*!< Database could not serialize access due to concurrent update, the transaction should be retried */,
245 OrthancPluginErrorCode_Revision = 43 /*!< A bad revision number was provided, which might indicate conflict between multiple writers */,
246 OrthancPluginErrorCode_SQLiteNotOpened = 1000 /*!< SQLite: The database is not opened */,
247 OrthancPluginErrorCode_SQLiteAlreadyOpened = 1001 /*!< SQLite: Connection is already open */,
248 OrthancPluginErrorCode_SQLiteCannotOpen = 1002 /*!< SQLite: Unable to open the database */,
249 OrthancPluginErrorCode_SQLiteStatementAlreadyUsed = 1003 /*!< SQLite: This cached statement is already being referred to */,
250 OrthancPluginErrorCode_SQLiteExecute = 1004 /*!< SQLite: Cannot execute a command */,
251 OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction = 1005 /*!< SQLite: Rolling back a nonexistent transaction (have you called Begin()?) */,
252 OrthancPluginErrorCode_SQLiteCommitWithoutTransaction = 1006 /*!< SQLite: Committing a nonexistent transaction */,
253 OrthancPluginErrorCode_SQLiteRegisterFunction = 1007 /*!< SQLite: Unable to register a function */,
254 OrthancPluginErrorCode_SQLiteFlush = 1008 /*!< SQLite: Unable to flush the database */,
255 OrthancPluginErrorCode_SQLiteCannotRun = 1009 /*!< SQLite: Cannot run a cached statement */,
256 OrthancPluginErrorCode_SQLiteCannotStep = 1010 /*!< SQLite: Cannot step over a cached statement */,
257 OrthancPluginErrorCode_SQLiteBindOutOfRange = 1011 /*!< SQLite: Bing a value while out of range (serious error) */,
258 OrthancPluginErrorCode_SQLitePrepareStatement = 1012 /*!< SQLite: Cannot prepare a cached statement */,
259 OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted = 1013 /*!< SQLite: Beginning the same transaction twice */,
260 OrthancPluginErrorCode_SQLiteTransactionCommit = 1014 /*!< SQLite: Failure when committing the transaction */,
261 OrthancPluginErrorCode_SQLiteTransactionBegin = 1015 /*!< SQLite: Cannot start a transaction */,
262 OrthancPluginErrorCode_DirectoryOverFile = 2000 /*!< The directory to be created is already occupied by a regular file */,
263 OrthancPluginErrorCode_FileStorageCannotWrite = 2001 /*!< Unable to create a subdirectory or a file in the file storage */,
264 OrthancPluginErrorCode_DirectoryExpected = 2002 /*!< The specified path does not point to a directory */,
265 OrthancPluginErrorCode_HttpPortInUse = 2003 /*!< The TCP port of the HTTP server is privileged or already in use */,
266 OrthancPluginErrorCode_DicomPortInUse = 2004 /*!< The TCP port of the DICOM server is privileged or already in use */,
267 OrthancPluginErrorCode_BadHttpStatusInRest = 2005 /*!< This HTTP status is not allowed in a REST API */,
268 OrthancPluginErrorCode_RegularFileExpected = 2006 /*!< The specified path does not point to a regular file */,
269 OrthancPluginErrorCode_PathToExecutable = 2007 /*!< Unable to get the path to the executable */,
270 OrthancPluginErrorCode_MakeDirectory = 2008 /*!< Cannot create a directory */,
271 OrthancPluginErrorCode_BadApplicationEntityTitle = 2009 /*!< An application entity title (AET) cannot be empty or be longer than 16 characters */,
272 OrthancPluginErrorCode_NoCFindHandler = 2010 /*!< No request handler factory for DICOM C-FIND SCP */,
273 OrthancPluginErrorCode_NoCMoveHandler = 2011 /*!< No request handler factory for DICOM C-MOVE SCP */,
274 OrthancPluginErrorCode_NoCStoreHandler = 2012 /*!< No request handler factory for DICOM C-STORE SCP */,
275 OrthancPluginErrorCode_NoApplicationEntityFilter = 2013 /*!< No application entity filter */,
276 OrthancPluginErrorCode_NoSopClassOrInstance = 2014 /*!< DicomUserConnection: Unable to find the SOP class and instance */,
277 OrthancPluginErrorCode_NoPresentationContext = 2015 /*!< DicomUserConnection: No acceptable presentation context for modality */,
278 OrthancPluginErrorCode_DicomFindUnavailable = 2016 /*!< DicomUserConnection: The C-FIND command is not supported by the remote SCP */,
279 OrthancPluginErrorCode_DicomMoveUnavailable = 2017 /*!< DicomUserConnection: The C-MOVE command is not supported by the remote SCP */,
280 OrthancPluginErrorCode_CannotStoreInstance = 2018 /*!< Cannot store an instance */,
281 OrthancPluginErrorCode_CreateDicomNotString = 2019 /*!< Only string values are supported when creating DICOM instances */,
282 OrthancPluginErrorCode_CreateDicomOverrideTag = 2020 /*!< Trying to override a value inherited from a parent module */,
283 OrthancPluginErrorCode_CreateDicomUseContent = 2021 /*!< Use \"Content\" to inject an image into a new DICOM instance */,
284 OrthancPluginErrorCode_CreateDicomNoPayload = 2022 /*!< No payload is present for one instance in the series */,
285 OrthancPluginErrorCode_CreateDicomUseDataUriScheme = 2023 /*!< The payload of the DICOM instance must be specified according to Data URI scheme */,
286 OrthancPluginErrorCode_CreateDicomBadParent = 2024 /*!< Trying to attach a new DICOM instance to an inexistent resource */,
287 OrthancPluginErrorCode_CreateDicomParentIsInstance = 2025 /*!< Trying to attach a new DICOM instance to an instance (must be a series, study or patient) */,
288 OrthancPluginErrorCode_CreateDicomParentEncoding = 2026 /*!< Unable to get the encoding of the parent resource */,
289 OrthancPluginErrorCode_UnknownModality = 2027 /*!< Unknown modality */,
290 OrthancPluginErrorCode_BadJobOrdering = 2028 /*!< Bad ordering of filters in a job */,
291 OrthancPluginErrorCode_JsonToLuaTable = 2029 /*!< Cannot convert the given JSON object to a Lua table */,
292 OrthancPluginErrorCode_CannotCreateLua = 2030 /*!< Cannot create the Lua context */,
293 OrthancPluginErrorCode_CannotExecuteLua = 2031 /*!< Cannot execute a Lua command */,
294 OrthancPluginErrorCode_LuaAlreadyExecuted = 2032 /*!< Arguments cannot be pushed after the Lua function is executed */,
295 OrthancPluginErrorCode_LuaBadOutput = 2033 /*!< The Lua function does not give the expected number of outputs */,
296 OrthancPluginErrorCode_NotLuaPredicate = 2034 /*!< The Lua function is not a predicate (only true/false outputs allowed) */,
297 OrthancPluginErrorCode_LuaReturnsNoString = 2035 /*!< The Lua function does not return a string */,
298 OrthancPluginErrorCode_StorageAreaAlreadyRegistered = 2036 /*!< Another plugin has already registered a custom storage area */,
299 OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered = 2037 /*!< Another plugin has already registered a custom database back-end */,
300 OrthancPluginErrorCode_DatabaseNotInitialized = 2038 /*!< Plugin trying to call the database during its initialization */,
301 OrthancPluginErrorCode_SslDisabled = 2039 /*!< Orthanc has been built without SSL support */,
302 OrthancPluginErrorCode_CannotOrderSlices = 2040 /*!< Unable to order the slices of the series */,
303 OrthancPluginErrorCode_NoWorklistHandler = 2041 /*!< No request handler factory for DICOM C-Find Modality SCP */,
304 OrthancPluginErrorCode_AlreadyExistingTag = 2042 /*!< Cannot override the value of a tag that already exists */,
305 OrthancPluginErrorCode_NoStorageCommitmentHandler = 2043 /*!< No request handler factory for DICOM N-ACTION SCP (storage commitment) */,
306 OrthancPluginErrorCode_NoCGetHandler = 2044 /*!< No request handler factory for DICOM C-GET SCP */,
307 OrthancPluginErrorCode_UnsupportedMediaType = 3000 /*!< Unsupported media type */,
308
309 _OrthancPluginErrorCode_INTERNAL = 0x7fffffff
310 } OrthancPluginErrorCode;
311
312
313 /**
314 * Forward declaration of one of the mandatory functions for Orthanc
315 * plugins.
316 **/
317 ORTHANC_PLUGINS_API const char* OrthancPluginGetName();
318
319
320 /**
321 * The various HTTP methods for a REST call.
322 **/
323 typedef enum
324 {
325 OrthancPluginHttpMethod_Get = 1, /*!< GET request */
326 OrthancPluginHttpMethod_Post = 2, /*!< POST request */
327 OrthancPluginHttpMethod_Put = 3, /*!< PUT request */
328 OrthancPluginHttpMethod_Delete = 4, /*!< DELETE request */
329
330 _OrthancPluginHttpMethod_INTERNAL = 0x7fffffff
331 } OrthancPluginHttpMethod;
332
333
334 /**
335 * @brief The parameters of a REST request.
336 * @ingroup Callbacks
337 **/
338 typedef struct
339 {
340 /**
341 * @brief The HTTP method.
342 **/
343 OrthancPluginHttpMethod method;
344
345 /**
346 * @brief The number of groups of the regular expression.
347 **/
348 uint32_t groupsCount;
349
350 /**
351 * @brief The matched values for the groups of the regular expression.
352 **/
353 const char* const* groups;
354
355 /**
356 * @brief For a GET request, the number of GET parameters.
357 **/
358 uint32_t getCount;
359
360 /**
361 * @brief For a GET request, the keys of the GET parameters.
362 **/
363 const char* const* getKeys;
364
365 /**
366 * @brief For a GET request, the values of the GET parameters.
367 **/
368 const char* const* getValues;
369
370 /**
371 * @brief For a PUT or POST request, the content of the body.
372 **/
373 const void* body;
374
375 /**
376 * @brief For a PUT or POST request, the number of bytes of the body.
377 **/
378 uint32_t bodySize;
379
380
381 /* --------------------------------------------------
382 New in version 0.8.1
383 -------------------------------------------------- */
384
385 /**
386 * @brief The number of HTTP headers.
387 **/
388 uint32_t headersCount;
389
390 /**
391 * @brief The keys of the HTTP headers (always converted to low-case).
392 **/
393 const char* const* headersKeys;
394
395 /**
396 * @brief The values of the HTTP headers.
397 **/
398 const char* const* headersValues;
399
400 } OrthancPluginHttpRequest;
401
402
403 typedef enum
404 {
405 /* Generic services */
406 _OrthancPluginService_LogInfo = 1,
407 _OrthancPluginService_LogWarning = 2,
408 _OrthancPluginService_LogError = 3,
409 _OrthancPluginService_GetOrthancPath = 4,
410 _OrthancPluginService_GetOrthancDirectory = 5,
411 _OrthancPluginService_GetConfigurationPath = 6,
412 _OrthancPluginService_SetPluginProperty = 7,
413 _OrthancPluginService_GetGlobalProperty = 8,
414 _OrthancPluginService_SetGlobalProperty = 9,
415 _OrthancPluginService_GetCommandLineArgumentsCount = 10,
416 _OrthancPluginService_GetCommandLineArgument = 11,
417 _OrthancPluginService_GetExpectedDatabaseVersion = 12,
418 _OrthancPluginService_GetConfiguration = 13,
419 _OrthancPluginService_BufferCompression = 14,
420 _OrthancPluginService_ReadFile = 15,
421 _OrthancPluginService_WriteFile = 16,
422 _OrthancPluginService_GetErrorDescription = 17,
423 _OrthancPluginService_CallHttpClient = 18,
424 _OrthancPluginService_RegisterErrorCode = 19,
425 _OrthancPluginService_RegisterDictionaryTag = 20,
426 _OrthancPluginService_DicomBufferToJson = 21,
427 _OrthancPluginService_DicomInstanceToJson = 22,
428 _OrthancPluginService_CreateDicom = 23,
429 _OrthancPluginService_ComputeMd5 = 24,
430 _OrthancPluginService_ComputeSha1 = 25,
431 _OrthancPluginService_LookupDictionary = 26,
432 _OrthancPluginService_CallHttpClient2 = 27,
433 _OrthancPluginService_GenerateUuid = 28,
434 _OrthancPluginService_RegisterPrivateDictionaryTag = 29,
435 _OrthancPluginService_AutodetectMimeType = 30,
436 _OrthancPluginService_SetMetricsValue = 31,
437 _OrthancPluginService_EncodeDicomWebJson = 32,
438 _OrthancPluginService_EncodeDicomWebXml = 33,
439 _OrthancPluginService_ChunkedHttpClient = 34, /* New in Orthanc 1.5.7 */
440 _OrthancPluginService_GetTagName = 35, /* New in Orthanc 1.5.7 */
441 _OrthancPluginService_EncodeDicomWebJson2 = 36, /* New in Orthanc 1.7.0 */
442 _OrthancPluginService_EncodeDicomWebXml2 = 37, /* New in Orthanc 1.7.0 */
443 _OrthancPluginService_CreateMemoryBuffer = 38, /* New in Orthanc 1.7.0 */
444 _OrthancPluginService_GenerateRestApiAuthorizationToken = 39, /* New in Orthanc 1.8.1 */
445 _OrthancPluginService_CreateMemoryBuffer64 = 40, /* New in Orthanc 1.9.0 */
446 _OrthancPluginService_CreateDicom2 = 41, /* New in Orthanc 1.9.0 */
447
448 /* Registration of callbacks */
449 _OrthancPluginService_RegisterRestCallback = 1000,
450 _OrthancPluginService_RegisterOnStoredInstanceCallback = 1001,
451 _OrthancPluginService_RegisterStorageArea = 1002,
452 _OrthancPluginService_RegisterOnChangeCallback = 1003,
453 _OrthancPluginService_RegisterRestCallbackNoLock = 1004,
454 _OrthancPluginService_RegisterWorklistCallback = 1005,
455 _OrthancPluginService_RegisterDecodeImageCallback = 1006,
456 _OrthancPluginService_RegisterIncomingHttpRequestFilter = 1007,
457 _OrthancPluginService_RegisterFindCallback = 1008,
458 _OrthancPluginService_RegisterMoveCallback = 1009,
459 _OrthancPluginService_RegisterIncomingHttpRequestFilter2 = 1010,
460 _OrthancPluginService_RegisterRefreshMetricsCallback = 1011,
461 _OrthancPluginService_RegisterChunkedRestCallback = 1012, /* New in Orthanc 1.5.7 */
462 _OrthancPluginService_RegisterStorageCommitmentScpCallback = 1013,
463 _OrthancPluginService_RegisterIncomingDicomInstanceFilter = 1014,
464 _OrthancPluginService_RegisterTranscoderCallback = 1015, /* New in Orthanc 1.7.0 */
465 _OrthancPluginService_RegisterStorageArea2 = 1016, /* New in Orthanc 1.9.0 */
466 _OrthancPluginService_RegisterIncomingCStoreInstanceFilter = 1017, /* New in Orthanc 1.10.0 */
467 _OrthancPluginService_RegisterReceivedInstanceCallback = 1018, /* New in Orthanc 1.10.0 */
468
469 /* Sending answers to REST calls */
470 _OrthancPluginService_AnswerBuffer = 2000,
471 _OrthancPluginService_CompressAndAnswerPngImage = 2001, /* Unused as of Orthanc 0.9.4 */
472 _OrthancPluginService_Redirect = 2002,
473 _OrthancPluginService_SendHttpStatusCode = 2003,
474 _OrthancPluginService_SendUnauthorized = 2004,
475 _OrthancPluginService_SendMethodNotAllowed = 2005,
476 _OrthancPluginService_SetCookie = 2006,
477 _OrthancPluginService_SetHttpHeader = 2007,
478 _OrthancPluginService_StartMultipartAnswer = 2008,
479 _OrthancPluginService_SendMultipartItem = 2009,
480 _OrthancPluginService_SendHttpStatus = 2010,
481 _OrthancPluginService_CompressAndAnswerImage = 2011,
482 _OrthancPluginService_SendMultipartItem2 = 2012,
483 _OrthancPluginService_SetHttpErrorDetails = 2013,
484
485 /* Access to the Orthanc database and API */
486 _OrthancPluginService_GetDicomForInstance = 3000,
487 _OrthancPluginService_RestApiGet = 3001,
488 _OrthancPluginService_RestApiPost = 3002,
489 _OrthancPluginService_RestApiDelete = 3003,
490 _OrthancPluginService_RestApiPut = 3004,
491 _OrthancPluginService_LookupPatient = 3005,
492 _OrthancPluginService_LookupStudy = 3006,
493 _OrthancPluginService_LookupSeries = 3007,
494 _OrthancPluginService_LookupInstance = 3008,
495 _OrthancPluginService_LookupStudyWithAccessionNumber = 3009,
496 _OrthancPluginService_RestApiGetAfterPlugins = 3010,
497 _OrthancPluginService_RestApiPostAfterPlugins = 3011,
498 _OrthancPluginService_RestApiDeleteAfterPlugins = 3012,
499 _OrthancPluginService_RestApiPutAfterPlugins = 3013,
500 _OrthancPluginService_ReconstructMainDicomTags = 3014,
501 _OrthancPluginService_RestApiGet2 = 3015,
502 _OrthancPluginService_CallRestApi = 3016, /* New in Orthanc 1.9.2 */
503
504 /* Access to DICOM instances */
505 _OrthancPluginService_GetInstanceRemoteAet = 4000,
506 _OrthancPluginService_GetInstanceSize = 4001,
507 _OrthancPluginService_GetInstanceData = 4002,
508 _OrthancPluginService_GetInstanceJson = 4003,
509 _OrthancPluginService_GetInstanceSimplifiedJson = 4004,
510 _OrthancPluginService_HasInstanceMetadata = 4005,
511 _OrthancPluginService_GetInstanceMetadata = 4006,
512 _OrthancPluginService_GetInstanceOrigin = 4007,
513 _OrthancPluginService_GetInstanceTransferSyntaxUid = 4008,
514 _OrthancPluginService_HasInstancePixelData = 4009,
515 _OrthancPluginService_CreateDicomInstance = 4010, /* New in Orthanc 1.7.0 */
516 _OrthancPluginService_FreeDicomInstance = 4011, /* New in Orthanc 1.7.0 */
517 _OrthancPluginService_GetInstanceFramesCount = 4012, /* New in Orthanc 1.7.0 */
518 _OrthancPluginService_GetInstanceRawFrame = 4013, /* New in Orthanc 1.7.0 */
519 _OrthancPluginService_GetInstanceDecodedFrame = 4014, /* New in Orthanc 1.7.0 */
520 _OrthancPluginService_TranscodeDicomInstance = 4015, /* New in Orthanc 1.7.0 */
521 _OrthancPluginService_SerializeDicomInstance = 4016, /* New in Orthanc 1.7.0 */
522 _OrthancPluginService_GetInstanceAdvancedJson = 4017, /* New in Orthanc 1.7.0 */
523 _OrthancPluginService_GetInstanceDicomWebJson = 4018, /* New in Orthanc 1.7.0 */
524 _OrthancPluginService_GetInstanceDicomWebXml = 4019, /* New in Orthanc 1.7.0 */
525
526 /* Services for plugins implementing a database back-end */
527 _OrthancPluginService_RegisterDatabaseBackend = 5000, /* New in Orthanc 0.8.6 */
528 _OrthancPluginService_DatabaseAnswer = 5001,
529 _OrthancPluginService_RegisterDatabaseBackendV2 = 5002, /* New in Orthanc 0.9.4 */
530 _OrthancPluginService_StorageAreaCreate = 5003,
531 _OrthancPluginService_StorageAreaRead = 5004,
532 _OrthancPluginService_StorageAreaRemove = 5005,
533 _OrthancPluginService_RegisterDatabaseBackendV3 = 5006, /* New in Orthanc 1.9.2 */
534
535 /* Primitives for handling images */
536 _OrthancPluginService_GetImagePixelFormat = 6000,
537 _OrthancPluginService_GetImageWidth = 6001,
538 _OrthancPluginService_GetImageHeight = 6002,
539 _OrthancPluginService_GetImagePitch = 6003,
540 _OrthancPluginService_GetImageBuffer = 6004,
541 _OrthancPluginService_UncompressImage = 6005,
542 _OrthancPluginService_FreeImage = 6006,
543 _OrthancPluginService_CompressImage = 6007,
544 _OrthancPluginService_ConvertPixelFormat = 6008,
545 _OrthancPluginService_GetFontsCount = 6009,
546 _OrthancPluginService_GetFontInfo = 6010,
547 _OrthancPluginService_DrawText = 6011,
548 _OrthancPluginService_CreateImage = 6012,
549 _OrthancPluginService_CreateImageAccessor = 6013,
550 _OrthancPluginService_DecodeDicomImage = 6014,
551
552 /* Primitives for handling C-Find, C-Move and worklists */
553 _OrthancPluginService_WorklistAddAnswer = 7000,
554 _OrthancPluginService_WorklistMarkIncomplete = 7001,
555 _OrthancPluginService_WorklistIsMatch = 7002,
556 _OrthancPluginService_WorklistGetDicomQuery = 7003,
557 _OrthancPluginService_FindAddAnswer = 7004,
558 _OrthancPluginService_FindMarkIncomplete = 7005,
559 _OrthancPluginService_GetFindQuerySize = 7006,
560 _OrthancPluginService_GetFindQueryTag = 7007,
561 _OrthancPluginService_GetFindQueryTagName = 7008,
562 _OrthancPluginService_GetFindQueryValue = 7009,
563 _OrthancPluginService_CreateFindMatcher = 7010,
564 _OrthancPluginService_FreeFindMatcher = 7011,
565 _OrthancPluginService_FindMatcherIsMatch = 7012,
566
567 /* Primitives for accessing Orthanc Peers (new in 1.4.2) */
568 _OrthancPluginService_GetPeers = 8000,
569 _OrthancPluginService_FreePeers = 8001,
570 _OrthancPluginService_GetPeersCount = 8003,
571 _OrthancPluginService_GetPeerName = 8004,
572 _OrthancPluginService_GetPeerUrl = 8005,
573 _OrthancPluginService_CallPeerApi = 8006,
574 _OrthancPluginService_GetPeerUserProperty = 8007,
575
576 /* Primitives for handling jobs (new in 1.4.2) */
577 _OrthancPluginService_CreateJob = 9000,
578 _OrthancPluginService_FreeJob = 9001,
579 _OrthancPluginService_SubmitJob = 9002,
580 _OrthancPluginService_RegisterJobsUnserializer = 9003,
581
582 _OrthancPluginService_INTERNAL = 0x7fffffff
583 } _OrthancPluginService;
584
585
586 typedef enum
587 {
588 _OrthancPluginProperty_Description = 1,
589 _OrthancPluginProperty_RootUri = 2,
590 _OrthancPluginProperty_OrthancExplorer = 3,
591
592 _OrthancPluginProperty_INTERNAL = 0x7fffffff
593 } _OrthancPluginProperty;
594
595
596
597 /**
598 * The memory layout of the pixels of an image.
599 * @ingroup Images
600 **/
601 typedef enum
602 {
603 /**
604 * @brief Graylevel 8bpp image.
605 *
606 * The image is graylevel. Each pixel is unsigned and stored in
607 * one byte.
608 **/
609 OrthancPluginPixelFormat_Grayscale8 = 1,
610
611 /**
612 * @brief Graylevel, unsigned 16bpp image.
613 *
614 * The image is graylevel. Each pixel is unsigned and stored in
615 * two bytes.
616 **/
617 OrthancPluginPixelFormat_Grayscale16 = 2,
618
619 /**
620 * @brief Graylevel, signed 16bpp image.
621 *
622 * The image is graylevel. Each pixel is signed and stored in two
623 * bytes.
624 **/
625 OrthancPluginPixelFormat_SignedGrayscale16 = 3,
626
627 /**
628 * @brief Color image in RGB24 format.
629 *
630 * This format describes a color image. The pixels are stored in 3
631 * consecutive bytes. The memory layout is RGB.
632 **/
633 OrthancPluginPixelFormat_RGB24 = 4,
634
635 /**
636 * @brief Color image in RGBA32 format.
637 *
638 * This format describes a color image. The pixels are stored in 4
639 * consecutive bytes. The memory layout is RGBA.
640 **/
641 OrthancPluginPixelFormat_RGBA32 = 5,
642
643 OrthancPluginPixelFormat_Unknown = 6, /*!< Unknown pixel format */
644
645 /**
646 * @brief Color image in RGB48 format.
647 *
648 * This format describes a color image. The pixels are stored in 6
649 * consecutive bytes. The memory layout is RRGGBB.
650 **/
651 OrthancPluginPixelFormat_RGB48 = 7,
652
653 /**
654 * @brief Graylevel, unsigned 32bpp image.
655 *
656 * The image is graylevel. Each pixel is unsigned and stored in
657 * four bytes.
658 **/
659 OrthancPluginPixelFormat_Grayscale32 = 8,
660
661 /**
662 * @brief Graylevel, floating-point 32bpp image.
663 *
664 * The image is graylevel. Each pixel is floating-point and stored
665 * in four bytes.
666 **/
667 OrthancPluginPixelFormat_Float32 = 9,
668
669 /**
670 * @brief Color image in BGRA32 format.
671 *
672 * This format describes a color image. The pixels are stored in 4
673 * consecutive bytes. The memory layout is BGRA.
674 **/
675 OrthancPluginPixelFormat_BGRA32 = 10,
676
677 /**
678 * @brief Graylevel, unsigned 64bpp image.
679 *
680 * The image is graylevel. Each pixel is unsigned and stored in
681 * eight bytes.
682 **/
683 OrthancPluginPixelFormat_Grayscale64 = 11,
684
685 _OrthancPluginPixelFormat_INTERNAL = 0x7fffffff
686 } OrthancPluginPixelFormat;
687
688
689
690 /**
691 * The content types that are supported by Orthanc plugins.
692 **/
693 typedef enum
694 {
695 OrthancPluginContentType_Unknown = 0, /*!< Unknown content type */
696 OrthancPluginContentType_Dicom = 1, /*!< DICOM */
697 OrthancPluginContentType_DicomAsJson = 2, /*!< JSON summary of a DICOM file */
698 OrthancPluginContentType_DicomUntilPixelData = 3, /*!< DICOM Header till pixel data */
699
700 _OrthancPluginContentType_INTERNAL = 0x7fffffff
701 } OrthancPluginContentType;
702
703
704
705 /**
706 * The supported types of DICOM resources.
707 **/
708 typedef enum
709 {
710 OrthancPluginResourceType_Patient = 0, /*!< Patient */
711 OrthancPluginResourceType_Study = 1, /*!< Study */
712 OrthancPluginResourceType_Series = 2, /*!< Series */
713 OrthancPluginResourceType_Instance = 3, /*!< Instance */
714 OrthancPluginResourceType_None = 4, /*!< Unavailable resource type */
715
716 _OrthancPluginResourceType_INTERNAL = 0x7fffffff
717 } OrthancPluginResourceType;
718
719
720
721 /**
722 * The supported types of changes that can be signaled to the change callback.
723 * @ingroup Callbacks
724 **/
725 typedef enum
726 {
727 OrthancPluginChangeType_CompletedSeries = 0, /*!< Series is now complete */
728 OrthancPluginChangeType_Deleted = 1, /*!< Deleted resource */
729 OrthancPluginChangeType_NewChildInstance = 2, /*!< A new instance was added to this resource */
730 OrthancPluginChangeType_NewInstance = 3, /*!< New instance received */
731 OrthancPluginChangeType_NewPatient = 4, /*!< New patient created */
732 OrthancPluginChangeType_NewSeries = 5, /*!< New series created */
733 OrthancPluginChangeType_NewStudy = 6, /*!< New study created */
734 OrthancPluginChangeType_StablePatient = 7, /*!< Timeout: No new instance in this patient */
735 OrthancPluginChangeType_StableSeries = 8, /*!< Timeout: No new instance in this series */
736 OrthancPluginChangeType_StableStudy = 9, /*!< Timeout: No new instance in this study */
737 OrthancPluginChangeType_OrthancStarted = 10, /*!< Orthanc has started */
738 OrthancPluginChangeType_OrthancStopped = 11, /*!< Orthanc is stopping */
739 OrthancPluginChangeType_UpdatedAttachment = 12, /*!< Some user-defined attachment has changed for this resource */
740 OrthancPluginChangeType_UpdatedMetadata = 13, /*!< Some user-defined metadata has changed for this resource */
741 OrthancPluginChangeType_UpdatedPeers = 14, /*!< The list of Orthanc peers has changed */
742 OrthancPluginChangeType_UpdatedModalities = 15, /*!< The list of DICOM modalities has changed */
743 OrthancPluginChangeType_JobSubmitted = 16, /*!< New Job submitted */
744 OrthancPluginChangeType_JobSuccess = 17, /*!< A Job has completed successfully */
745 OrthancPluginChangeType_JobFailure = 18, /*!< A Job has failed */
746
747 _OrthancPluginChangeType_INTERNAL = 0x7fffffff
748 } OrthancPluginChangeType;
749
750
751 /**
752 * The compression algorithms that are supported by the Orthanc core.
753 * @ingroup Images
754 **/
755 typedef enum
756 {
757 OrthancPluginCompressionType_Zlib = 0, /*!< Standard zlib compression */
758 OrthancPluginCompressionType_ZlibWithSize = 1, /*!< zlib, prefixed with uncompressed size (uint64_t) */
759 OrthancPluginCompressionType_Gzip = 2, /*!< Standard gzip compression */
760 OrthancPluginCompressionType_GzipWithSize = 3, /*!< gzip, prefixed with uncompressed size (uint64_t) */
761
762 _OrthancPluginCompressionType_INTERNAL = 0x7fffffff
763 } OrthancPluginCompressionType;
764
765
766 /**
767 * The image formats that are supported by the Orthanc core.
768 * @ingroup Images
769 **/
770 typedef enum
771 {
772 OrthancPluginImageFormat_Png = 0, /*!< Image compressed using PNG */
773 OrthancPluginImageFormat_Jpeg = 1, /*!< Image compressed using JPEG */
774 OrthancPluginImageFormat_Dicom = 2, /*!< Image compressed using DICOM */
775
776 _OrthancPluginImageFormat_INTERNAL = 0x7fffffff
777 } OrthancPluginImageFormat;
778
779
780 /**
781 * The value representations present in the DICOM standard (version 2013).
782 * @ingroup Toolbox
783 **/
784 typedef enum
785 {
786 OrthancPluginValueRepresentation_AE = 1, /*!< Application Entity */
787 OrthancPluginValueRepresentation_AS = 2, /*!< Age String */
788 OrthancPluginValueRepresentation_AT = 3, /*!< Attribute Tag */
789 OrthancPluginValueRepresentation_CS = 4, /*!< Code String */
790 OrthancPluginValueRepresentation_DA = 5, /*!< Date */
791 OrthancPluginValueRepresentation_DS = 6, /*!< Decimal String */
792 OrthancPluginValueRepresentation_DT = 7, /*!< Date Time */
793 OrthancPluginValueRepresentation_FD = 8, /*!< Floating Point Double */
794 OrthancPluginValueRepresentation_FL = 9, /*!< Floating Point Single */
795 OrthancPluginValueRepresentation_IS = 10, /*!< Integer String */
796 OrthancPluginValueRepresentation_LO = 11, /*!< Long String */
797 OrthancPluginValueRepresentation_LT = 12, /*!< Long Text */
798 OrthancPluginValueRepresentation_OB = 13, /*!< Other Byte String */
799 OrthancPluginValueRepresentation_OF = 14, /*!< Other Float String */
800 OrthancPluginValueRepresentation_OW = 15, /*!< Other Word String */
801 OrthancPluginValueRepresentation_PN = 16, /*!< Person Name */
802 OrthancPluginValueRepresentation_SH = 17, /*!< Short String */
803 OrthancPluginValueRepresentation_SL = 18, /*!< Signed Long */
804 OrthancPluginValueRepresentation_SQ = 19, /*!< Sequence of Items */
805 OrthancPluginValueRepresentation_SS = 20, /*!< Signed Short */
806 OrthancPluginValueRepresentation_ST = 21, /*!< Short Text */
807 OrthancPluginValueRepresentation_TM = 22, /*!< Time */
808 OrthancPluginValueRepresentation_UI = 23, /*!< Unique Identifier (UID) */
809 OrthancPluginValueRepresentation_UL = 24, /*!< Unsigned Long */
810 OrthancPluginValueRepresentation_UN = 25, /*!< Unknown */
811 OrthancPluginValueRepresentation_US = 26, /*!< Unsigned Short */
812 OrthancPluginValueRepresentation_UT = 27, /*!< Unlimited Text */
813
814 _OrthancPluginValueRepresentation_INTERNAL = 0x7fffffff
815 } OrthancPluginValueRepresentation;
816
817
818 /**
819 * The possible output formats for a DICOM-to-JSON conversion.
820 * @ingroup Toolbox
821 * @see OrthancPluginDicomToJson()
822 **/
823 typedef enum
824 {
825 OrthancPluginDicomToJsonFormat_Full = 1, /*!< Full output, with most details */
826 OrthancPluginDicomToJsonFormat_Short = 2, /*!< Tags output as hexadecimal numbers */
827 OrthancPluginDicomToJsonFormat_Human = 3, /*!< Human-readable JSON */
828
829 _OrthancPluginDicomToJsonFormat_INTERNAL = 0x7fffffff
830 } OrthancPluginDicomToJsonFormat;
831
832
833 /**
834 * Flags to customize a DICOM-to-JSON conversion. By default, binary
835 * tags are formatted using Data URI scheme.
836 * @ingroup Toolbox
837 **/
838 typedef enum
839 {
840 OrthancPluginDicomToJsonFlags_None = 0, /*!< Default formatting */
841 OrthancPluginDicomToJsonFlags_IncludeBinary = (1 << 0), /*!< Include the binary tags */
842 OrthancPluginDicomToJsonFlags_IncludePrivateTags = (1 << 1), /*!< Include the private tags */
843 OrthancPluginDicomToJsonFlags_IncludeUnknownTags = (1 << 2), /*!< Include the tags unknown by the dictionary */
844 OrthancPluginDicomToJsonFlags_IncludePixelData = (1 << 3), /*!< Include the pixel data */
845 OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii = (1 << 4), /*!< Output binary tags as-is, dropping non-ASCII */
846 OrthancPluginDicomToJsonFlags_ConvertBinaryToNull = (1 << 5), /*!< Signal binary tags as null values */
847 OrthancPluginDicomToJsonFlags_StopAfterPixelData = (1 << 6), /*!< Stop processing after pixel data (new in 1.9.1) */
848 OrthancPluginDicomToJsonFlags_SkipGroupLengths = (1 << 7), /*!< Skip tags whose element is zero (new in 1.9.1) */
849
850 _OrthancPluginDicomToJsonFlags_INTERNAL = 0x7fffffff
851 } OrthancPluginDicomToJsonFlags;
852
853
854 /**
855 * Flags to the creation of a DICOM file.
856 * @ingroup Toolbox
857 * @see OrthancPluginCreateDicom()
858 **/
859 typedef enum
860 {
861 OrthancPluginCreateDicomFlags_None = 0, /*!< Default mode */
862 OrthancPluginCreateDicomFlags_DecodeDataUriScheme = (1 << 0), /*!< Decode fields encoded using data URI scheme */
863 OrthancPluginCreateDicomFlags_GenerateIdentifiers = (1 << 1), /*!< Automatically generate DICOM identifiers */
864
865 _OrthancPluginCreateDicomFlags_INTERNAL = 0x7fffffff
866 } OrthancPluginCreateDicomFlags;
867
868
869 /**
870 * The constraints on the DICOM identifiers that must be supported
871 * by the database plugins.
872 * @deprecated Plugins using OrthancPluginConstraintType will be faster
873 **/
874 typedef enum
875 {
876 OrthancPluginIdentifierConstraint_Equal = 1, /*!< Equal */
877 OrthancPluginIdentifierConstraint_SmallerOrEqual = 2, /*!< Less or equal */
878 OrthancPluginIdentifierConstraint_GreaterOrEqual = 3, /*!< More or equal */
879 OrthancPluginIdentifierConstraint_Wildcard = 4, /*!< Case-sensitive wildcard matching (with * and ?) */
880
881 _OrthancPluginIdentifierConstraint_INTERNAL = 0x7fffffff
882 } OrthancPluginIdentifierConstraint;
883
884
885 /**
886 * The constraints on the tags (main DICOM tags and identifier tags)
887 * that must be supported by the database plugins.
888 **/
889 typedef enum
890 {
891 OrthancPluginConstraintType_Equal = 1, /*!< Equal */
892 OrthancPluginConstraintType_SmallerOrEqual = 2, /*!< Less or equal */
893 OrthancPluginConstraintType_GreaterOrEqual = 3, /*!< More or equal */
894 OrthancPluginConstraintType_Wildcard = 4, /*!< Wildcard matching */
895 OrthancPluginConstraintType_List = 5, /*!< List of values */
896
897 _OrthancPluginConstraintType_INTERNAL = 0x7fffffff
898 } OrthancPluginConstraintType;
899
900
901 /**
902 * The origin of a DICOM instance that has been received by Orthanc.
903 **/
904 typedef enum
905 {
906 OrthancPluginInstanceOrigin_Unknown = 1, /*!< Unknown origin */
907 OrthancPluginInstanceOrigin_DicomProtocol = 2, /*!< Instance received through DICOM protocol */
908 OrthancPluginInstanceOrigin_RestApi = 3, /*!< Instance received through REST API of Orthanc */
909 OrthancPluginInstanceOrigin_Plugin = 4, /*!< Instance added to Orthanc by a plugin */
910 OrthancPluginInstanceOrigin_Lua = 5, /*!< Instance added to Orthanc by a Lua script */
911 OrthancPluginInstanceOrigin_WebDav = 6, /*!< Instance received through WebDAV (new in 1.8.0) */
912
913 _OrthancPluginInstanceOrigin_INTERNAL = 0x7fffffff
914 } OrthancPluginInstanceOrigin;
915
916
917 /**
918 * The possible status for one single step of a job.
919 **/
920 typedef enum
921 {
922 OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */
923 OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */
924 OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */
925 } OrthancPluginJobStepStatus;
926
927
928 /**
929 * Explains why the job should stop and release the resources it has
930 * allocated. This is especially important to disambiguate between
931 * the "paused" condition and the "final" conditions (success,
932 * failure, or canceled).
933 **/
934 typedef enum
935 {
936 OrthancPluginJobStopReason_Success = 1, /*!< The job has succeeded */
937 OrthancPluginJobStopReason_Paused = 2, /*!< The job was paused, and will be resumed later */
938 OrthancPluginJobStopReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */
939 OrthancPluginJobStopReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */
940 } OrthancPluginJobStopReason;
941
942
943 /**
944 * The available types of metrics.
945 **/
946 typedef enum
947 {
948 OrthancPluginMetricsType_Default = 0, /*!< Default metrics */
949
950 /**
951 * This metrics represents a time duration. Orthanc will keep the
952 * maximum value of the metrics over a sliding window of ten
953 * seconds, which is useful if the metrics is sampled frequently.
954 **/
955 OrthancPluginMetricsType_Timer = 1
956 } OrthancPluginMetricsType;
957
958
959 /**
960 * The available modes to export a binary DICOM tag into a DICOMweb
961 * JSON or XML document.
962 **/
963 typedef enum
964 {
965 OrthancPluginDicomWebBinaryMode_Ignore = 0, /*!< Don't include binary tags */
966 OrthancPluginDicomWebBinaryMode_InlineBinary = 1, /*!< Inline encoding using Base64 */
967 OrthancPluginDicomWebBinaryMode_BulkDataUri = 2 /*!< Use a bulk data URI field */
968 } OrthancPluginDicomWebBinaryMode;
969
970
971 /**
972 * The available values for the Failure Reason (0008,1197) during
973 * storage commitment.
974 * http://dicom.nema.org/medical/dicom/2019e/output/chtml/part03/sect_C.14.html#sect_C.14.1.1
975 **/
976 typedef enum
977 {
978 /**
979 * Success: The DICOM instance is properly stored in the SCP
980 **/
981 OrthancPluginStorageCommitmentFailureReason_Success = 0,
982
983 /**
984 * 0110H: A general failure in processing the operation was encountered
985 **/
986 OrthancPluginStorageCommitmentFailureReason_ProcessingFailure = 1,
987
988 /**
989 * 0112H: One or more of the elements in the Referenced SOP
990 * Instance Sequence was not available
991 **/
992 OrthancPluginStorageCommitmentFailureReason_NoSuchObjectInstance = 2,
993
994 /**
995 * 0213H: The SCP does not currently have enough resources to
996 * store the requested SOP Instance(s)
997 **/
998 OrthancPluginStorageCommitmentFailureReason_ResourceLimitation = 3,
999
1000 /**
1001 * 0122H: Storage Commitment has been requested for a SOP Instance
1002 * with a SOP Class that is not supported by the SCP
1003 **/
1004 OrthancPluginStorageCommitmentFailureReason_ReferencedSOPClassNotSupported = 4,
1005
1006 /**
1007 * 0119H: The SOP Class of an element in the Referenced SOP
1008 * Instance Sequence did not correspond to the SOP class
1009 * registered for this SOP Instance at the SCP
1010 **/
1011 OrthancPluginStorageCommitmentFailureReason_ClassInstanceConflict = 5,
1012
1013 /**
1014 * 0131H: The Transaction UID of the Storage Commitment Request is
1015 * already in use
1016 **/
1017 OrthancPluginStorageCommitmentFailureReason_DuplicateTransactionUID = 6
1018 } OrthancPluginStorageCommitmentFailureReason;
1019
1020
1021 /**
1022 * The action to be taken after ReceivedInstanceCallback is triggered
1023 **/
1024 typedef enum
1025 {
1026 OrthancPluginReceivedInstanceAction_KeepAsIs = 1, /*!< Keep the instance as is */
1027 OrthancPluginReceivedInstanceAction_Modify = 2, /*!< Modify the instance */
1028 OrthancPluginReceivedInstanceAction_Discard = 3, /*!< Discard the instance */
1029
1030 _OrthancPluginReceivedInstanceAction_INTERNAL = 0x7fffffff
1031 } OrthancPluginReceivedInstanceAction;
1032
1033
1034 /**
1035 * @brief A 32-bit memory buffer allocated by the core system of Orthanc.
1036 *
1037 * A memory buffer allocated by the core system of Orthanc. When the
1038 * content of the buffer is not useful anymore, it must be free by a
1039 * call to ::OrthancPluginFreeMemoryBuffer().
1040 **/
1041 typedef struct
1042 {
1043 /**
1044 * @brief The content of the buffer.
1045 **/
1046 void* data;
1047
1048 /**
1049 * @brief The number of bytes in the buffer.
1050 **/
1051 uint32_t size;
1052 } OrthancPluginMemoryBuffer;
1053
1054
1055
1056 /**
1057 * @brief A 64-bit memory buffer allocated by the core system of Orthanc.
1058 *
1059 * A memory buffer allocated by the core system of Orthanc. When the
1060 * content of the buffer is not useful anymore, it must be free by a
1061 * call to ::OrthancPluginFreeMemoryBuffer64().
1062 **/
1063 typedef struct
1064 {
1065 /**
1066 * @brief The content of the buffer.
1067 **/
1068 void* data;
1069
1070 /**
1071 * @brief The number of bytes in the buffer.
1072 **/
1073 uint64_t size;
1074 } OrthancPluginMemoryBuffer64;
1075
1076
1077
1078
1079 /**
1080 * @brief Opaque structure that represents the HTTP connection to the client application.
1081 * @ingroup Callback
1082 **/
1083 typedef struct _OrthancPluginRestOutput_t OrthancPluginRestOutput;
1084
1085
1086
1087 /**
1088 * @brief Opaque structure that represents a DICOM instance that is managed by the Orthanc core.
1089 * @ingroup DicomInstance
1090 **/
1091 typedef struct _OrthancPluginDicomInstance_t OrthancPluginDicomInstance;
1092
1093
1094
1095 /**
1096 * @brief Opaque structure that represents an image that is uncompressed in memory.
1097 * @ingroup Images
1098 **/
1099 typedef struct _OrthancPluginImage_t OrthancPluginImage;
1100
1101
1102
1103 /**
1104 * @brief Opaque structure that represents the storage area that is actually used by Orthanc.
1105 * @ingroup Images
1106 **/
1107 typedef struct _OrthancPluginStorageArea_t OrthancPluginStorageArea;
1108
1109
1110
1111 /**
1112 * @brief Opaque structure to an object that represents a C-Find query for worklists.
1113 * @ingroup DicomCallbacks
1114 **/
1115 typedef struct _OrthancPluginWorklistQuery_t OrthancPluginWorklistQuery;
1116
1117
1118
1119 /**
1120 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1121 * @ingroup DicomCallbacks
1122 **/
1123 typedef struct _OrthancPluginWorklistAnswers_t OrthancPluginWorklistAnswers;
1124
1125
1126
1127 /**
1128 * @brief Opaque structure to an object that represents a C-Find query.
1129 * @ingroup DicomCallbacks
1130 **/
1131 typedef struct _OrthancPluginFindQuery_t OrthancPluginFindQuery;
1132
1133
1134
1135 /**
1136 * @brief Opaque structure to an object that represents the answers to a C-Find query for worklists.
1137 * @ingroup DicomCallbacks
1138 **/
1139 typedef struct _OrthancPluginFindAnswers_t OrthancPluginFindAnswers;
1140
1141
1142
1143 /**
1144 * @brief Opaque structure to an object that can be used to check whether a DICOM instance matches a C-Find query.
1145 * @ingroup Toolbox
1146 **/
1147 typedef struct _OrthancPluginFindMatcher_t OrthancPluginFindMatcher;
1148
1149
1150
1151 /**
1152 * @brief Opaque structure to the set of remote Orthanc Peers that are known to the local Orthanc server.
1153 * @ingroup Toolbox
1154 **/
1155 typedef struct _OrthancPluginPeers_t OrthancPluginPeers;
1156
1157
1158
1159 /**
1160 * @brief Opaque structure to a job to be executed by Orthanc.
1161 * @ingroup Toolbox
1162 **/
1163 typedef struct _OrthancPluginJob_t OrthancPluginJob;
1164
1165
1166
1167 /**
1168 * @brief Opaque structure that represents a node in a JSON or XML
1169 * document used in DICOMweb.
1170 * @ingroup Toolbox
1171 **/
1172 typedef struct _OrthancPluginDicomWebNode_t OrthancPluginDicomWebNode;
1173
1174
1175
1176 /**
1177 * @brief Signature of a callback function that answers to a REST request.
1178 * @ingroup Callbacks
1179 **/
1180 typedef OrthancPluginErrorCode (*OrthancPluginRestCallback) (
1181 OrthancPluginRestOutput* output,
1182 const char* url,
1183 const OrthancPluginHttpRequest* request);
1184
1185
1186
1187 /**
1188 * @brief Signature of a callback function that is triggered when Orthanc stores a new DICOM instance.
1189 * @ingroup Callbacks
1190 **/
1191 typedef OrthancPluginErrorCode (*OrthancPluginOnStoredInstanceCallback) (
1192 const OrthancPluginDicomInstance* instance,
1193 const char* instanceId);
1194
1195
1196
1197 /**
1198 * @brief Signature of a callback function that is triggered when a change happens to some DICOM resource.
1199 * @ingroup Callbacks
1200 **/
1201 typedef OrthancPluginErrorCode (*OrthancPluginOnChangeCallback) (
1202 OrthancPluginChangeType changeType,
1203 OrthancPluginResourceType resourceType,
1204 const char* resourceId);
1205
1206
1207
1208 /**
1209 * @brief Signature of a callback function to decode a DICOM instance as an image.
1210 * @ingroup Callbacks
1211 **/
1212 typedef OrthancPluginErrorCode (*OrthancPluginDecodeImageCallback) (
1213 OrthancPluginImage** target,
1214 const void* dicom,
1215 const uint32_t size,
1216 uint32_t frameIndex);
1217
1218
1219
1220 /**
1221 * @brief Signature of a function to free dynamic memory.
1222 * @ingroup Callbacks
1223 **/
1224 typedef void (*OrthancPluginFree) (void* buffer);
1225
1226
1227
1228 /**
1229 * @brief Signature of a function to set the content of a node
1230 * encoding a binary DICOM tag, into a JSON or XML document
1231 * generated for DICOMweb.
1232 * @ingroup Callbacks
1233 **/
1234 typedef void (*OrthancPluginDicomWebSetBinaryNode) (
1235 OrthancPluginDicomWebNode* node,
1236 OrthancPluginDicomWebBinaryMode mode,
1237 const char* bulkDataUri);
1238
1239
1240
1241 /**
1242 * @brief Callback for writing to the storage area.
1243 *
1244 * Signature of a callback function that is triggered when Orthanc writes a file to the storage area.
1245 *
1246 * @param uuid The UUID of the file.
1247 * @param content The content of the file.
1248 * @param size The size of the file.
1249 * @param type The content type corresponding to this file.
1250 * @return 0 if success, other value if error.
1251 * @ingroup Callbacks
1252 **/
1253 typedef OrthancPluginErrorCode (*OrthancPluginStorageCreate) (
1254 const char* uuid,
1255 const void* content,
1256 int64_t size,
1257 OrthancPluginContentType type);
1258
1259
1260
1261 /**
1262 * @brief Callback for reading from the storage area.
1263 *
1264 * Signature of a callback function that is triggered when Orthanc reads a file from the storage area.
1265 *
1266 * @param content The content of the file (output).
1267 * @param size The size of the file (output).
1268 * @param uuid The UUID of the file of interest.
1269 * @param type The content type corresponding to this file.
1270 * @return 0 if success, other value if error.
1271 * @ingroup Callbacks
1272 * @deprecated New plugins should use OrthancPluginStorageRead2
1273 *
1274 * @warning The "content" buffer *must* have been allocated using
1275 * the "malloc()" function of your C standard library (i.e. nor
1276 * "new[]", neither a pointer to a buffer). The "free()" function of
1277 * your C standard library will automatically be invoked on the
1278 * "content" pointer.
1279 **/
1280 typedef OrthancPluginErrorCode (*OrthancPluginStorageRead) (
1281 void** content,
1282 int64_t* size,
1283 const char* uuid,
1284 OrthancPluginContentType type);
1285
1286
1287
1288 /**
1289 * @brief Callback for reading a whole file from the storage area.
1290 *
1291 * Signature of a callback function that is triggered when Orthanc
1292 * reads a whole file from the storage area.
1293 *
1294 * @param target Memory buffer where to store the content of the file. It must be allocated by the
1295 * plugin using OrthancPluginCreateMemoryBuffer64(). The core of Orthanc will free it.
1296 * @param uuid The UUID of the file of interest.
1297 * @param type The content type corresponding to this file.
1298 * @ingroup Callbacks
1299 **/
1300 typedef OrthancPluginErrorCode (*OrthancPluginStorageReadWhole) (
1301 OrthancPluginMemoryBuffer64* target,
1302 const char* uuid,
1303 OrthancPluginContentType type);
1304
1305
1306
1307 /**
1308 * @brief Callback for reading a range of a file from the storage area.
1309 *
1310 * Signature of a callback function that is triggered when Orthanc
1311 * reads a portion of a file from the storage area. Orthanc
1312 * indicates the start position and the length of the range.
1313 *
1314 * @param target Memory buffer where to store the content of the range.
1315 * The memory buffer is allocated and freed by Orthanc. The length of the range
1316 * of interest corresponds to the size of this buffer.
1317 * @param uuid The UUID of the file of interest.
1318 * @param type The content type corresponding to this file.
1319 * @param rangeStart Start position of the requested range in the file.
1320 * @return 0 if success, other value if error.
1321 * @ingroup Callbacks
1322 **/
1323 typedef OrthancPluginErrorCode (*OrthancPluginStorageReadRange) (
1324 OrthancPluginMemoryBuffer64* target,
1325 const char* uuid,
1326 OrthancPluginContentType type,
1327 uint64_t rangeStart);
1328
1329
1330
1331 /**
1332 * @brief Callback for removing a file from the storage area.
1333 *
1334 * Signature of a callback function that is triggered when Orthanc deletes a file from the storage area.
1335 *
1336 * @param uuid The UUID of the file to be removed.
1337 * @param type The content type corresponding to this file.
1338 * @return 0 if success, other value if error.
1339 * @ingroup Callbacks
1340 **/
1341 typedef OrthancPluginErrorCode (*OrthancPluginStorageRemove) (
1342 const char* uuid,
1343 OrthancPluginContentType type);
1344
1345
1346
1347 /**
1348 * @brief Callback to handle the C-Find SCP requests for worklists.
1349 *
1350 * Signature of a callback function that is triggered when Orthanc
1351 * receives a C-Find SCP request against modality worklists.
1352 *
1353 * @param answers The target structure where answers must be stored.
1354 * @param query The worklist query.
1355 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1356 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1357 * @return 0 if success, other value if error.
1358 * @ingroup DicomCallbacks
1359 **/
1360 typedef OrthancPluginErrorCode (*OrthancPluginWorklistCallback) (
1361 OrthancPluginWorklistAnswers* answers,
1362 const OrthancPluginWorklistQuery* query,
1363 const char* issuerAet,
1364 const char* calledAet);
1365
1366
1367
1368 /**
1369 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1370 *
1371 * Signature of a callback function that is triggered whenever
1372 * Orthanc receives an HTTP/REST request, and that answers whether
1373 * this request should be allowed. If the callback returns "0"
1374 * ("false"), the server answers with HTTP status code 403
1375 * (Forbidden).
1376 *
1377 * Pay attention to the fact that this function may be invoked
1378 * concurrently by different threads of the Web server of
1379 * Orthanc. You must implement proper locking if applicable.
1380 *
1381 * @param method The HTTP method used by the request.
1382 * @param uri The URI of interest.
1383 * @param ip The IP address of the HTTP client.
1384 * @param headersCount The number of HTTP headers.
1385 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1386 * @param headersValues The values of the HTTP headers.
1387 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1388 * @ingroup Callback
1389 * @deprecated Please instead use OrthancPluginIncomingHttpRequestFilter2()
1390 **/
1391 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter) (
1392 OrthancPluginHttpMethod method,
1393 const char* uri,
1394 const char* ip,
1395 uint32_t headersCount,
1396 const char* const* headersKeys,
1397 const char* const* headersValues);
1398
1399
1400
1401 /**
1402 * @brief Callback to filter incoming HTTP requests received by Orthanc.
1403 *
1404 * Signature of a callback function that is triggered whenever
1405 * Orthanc receives an HTTP/REST request, and that answers whether
1406 * this request should be allowed. If the callback returns "0"
1407 * ("false"), the server answers with HTTP status code 403
1408 * (Forbidden).
1409 *
1410 * Pay attention to the fact that this function may be invoked
1411 * concurrently by different threads of the Web server of
1412 * Orthanc. You must implement proper locking if applicable.
1413 *
1414 * @param method The HTTP method used by the request.
1415 * @param uri The URI of interest.
1416 * @param ip The IP address of the HTTP client.
1417 * @param headersCount The number of HTTP headers.
1418 * @param headersKeys The keys of the HTTP headers (always converted to low-case).
1419 * @param headersValues The values of the HTTP headers.
1420 * @param getArgumentsCount The number of GET arguments (only for the GET HTTP method).
1421 * @param getArgumentsKeys The keys of the GET arguments (only for the GET HTTP method).
1422 * @param getArgumentsValues The values of the GET arguments (only for the GET HTTP method).
1423 * @return 0 if forbidden access, 1 if allowed access, -1 if error.
1424 * @ingroup Callback
1425 **/
1426 typedef int32_t (*OrthancPluginIncomingHttpRequestFilter2) (
1427 OrthancPluginHttpMethod method,
1428 const char* uri,
1429 const char* ip,
1430 uint32_t headersCount,
1431 const char* const* headersKeys,
1432 const char* const* headersValues,
1433 uint32_t getArgumentsCount,
1434 const char* const* getArgumentsKeys,
1435 const char* const* getArgumentsValues);
1436
1437
1438
1439 /**
1440 * @brief Callback to handle incoming C-Find SCP requests.
1441 *
1442 * Signature of a callback function that is triggered whenever
1443 * Orthanc receives a C-Find SCP request not concerning modality
1444 * worklists.
1445 *
1446 * @param answers The target structure where answers must be stored.
1447 * @param query The worklist query.
1448 * @param issuerAet The Application Entity Title (AET) of the modality from which the request originates.
1449 * @param calledAet The Application Entity Title (AET) of the modality that is called by the request.
1450 * @return 0 if success, other value if error.
1451 * @ingroup DicomCallbacks
1452 **/
1453 typedef OrthancPluginErrorCode (*OrthancPluginFindCallback) (
1454 OrthancPluginFindAnswers* answers,
1455 const OrthancPluginFindQuery* query,
1456 const char* issuerAet,
1457 const char* calledAet);
1458
1459
1460
1461 /**
1462 * @brief Callback to handle incoming C-Move SCP requests.
1463 *
1464 * Signature of a callback function that is triggered whenever
1465 * Orthanc receives a C-Move SCP request. The callback receives the
1466 * type of the resource of interest (study, series, instance...)
1467 * together with the DICOM tags containing its identifiers. In turn,
1468 * the plugin must create a driver object that will be responsible
1469 * for driving the successive move suboperations.
1470 *
1471 * @param resourceType The type of the resource of interest. Note
1472 * that this might be set to ResourceType_None if the
1473 * QueryRetrieveLevel (0008,0052) tag was not provided by the
1474 * issuer (i.e. the originator modality).
1475 * @param patientId Content of the PatientID (0x0010, 0x0020) tag of the resource of interest. Might be NULL.
1476 * @param accessionNumber Content of the AccessionNumber (0x0008, 0x0050) tag. Might be NULL.
1477 * @param studyInstanceUid Content of the StudyInstanceUID (0x0020, 0x000d) tag. Might be NULL.
1478 * @param seriesInstanceUid Content of the SeriesInstanceUID (0x0020, 0x000e) tag. Might be NULL.
1479 * @param sopInstanceUid Content of the SOPInstanceUID (0x0008, 0x0018) tag. Might be NULL.
1480 * @param originatorAet The Application Entity Title (AET) of the
1481 * modality from which the request originates.
1482 * @param sourceAet The Application Entity Title (AET) of the
1483 * modality that should send its DICOM files to another modality.
1484 * @param targetAet The Application Entity Title (AET) of the
1485 * modality that should receive the DICOM files.
1486 * @param originatorId The Message ID issued by the originator modality,
1487 * as found in tag (0000,0110) of the DICOM query emitted by the issuer.
1488 *
1489 * @return The NULL value if the plugin cannot deal with this query,
1490 * or a pointer to the driver object that is responsible for
1491 * handling the successive move suboperations.
1492 *
1493 * @note If targetAet equals sourceAet, this is actually a query/retrieve operation.
1494 * @ingroup DicomCallbacks
1495 **/
1496 typedef void* (*OrthancPluginMoveCallback) (
1497 OrthancPluginResourceType resourceType,
1498 const char* patientId,
1499 const char* accessionNumber,
1500 const char* studyInstanceUid,
1501 const char* seriesInstanceUid,
1502 const char* sopInstanceUid,
1503 const char* originatorAet,
1504 const char* sourceAet,
1505 const char* targetAet,
1506 uint16_t originatorId);
1507
1508
1509 /**
1510 * @brief Callback to read the size of a C-Move driver.
1511 *
1512 * Signature of a callback function that returns the number of
1513 * C-Move suboperations that are to be achieved by the given C-Move
1514 * driver. This driver is the return value of a previous call to the
1515 * OrthancPluginMoveCallback() callback.
1516 *
1517 * @param moveDriver The C-Move driver of interest.
1518 * @return The number of suboperations.
1519 * @ingroup DicomCallbacks
1520 **/
1521 typedef uint32_t (*OrthancPluginGetMoveSize) (void* moveDriver);
1522
1523
1524 /**
1525 * @brief Callback to apply one C-Move suboperation.
1526 *
1527 * Signature of a callback function that applies the next C-Move
1528 * suboperation that os to be achieved by the given C-Move
1529 * driver. This driver is the return value of a previous call to the
1530 * OrthancPluginMoveCallback() callback.
1531 *
1532 * @param moveDriver The C-Move driver of interest.
1533 * @return 0 if success, or the error code if failure.
1534 * @ingroup DicomCallbacks
1535 **/
1536 typedef OrthancPluginErrorCode (*OrthancPluginApplyMove) (void* moveDriver);
1537
1538
1539 /**
1540 * @brief Callback to free one C-Move driver.
1541 *
1542 * Signature of a callback function that releases the resources
1543 * allocated by the given C-Move driver. This driver is the return
1544 * value of a previous call to the OrthancPluginMoveCallback()
1545 * callback.
1546 *
1547 * @param moveDriver The C-Move driver of interest.
1548 * @ingroup DicomCallbacks
1549 **/
1550 typedef void (*OrthancPluginFreeMove) (void* moveDriver);
1551
1552
1553 /**
1554 * @brief Callback to finalize one custom job.
1555 *
1556 * Signature of a callback function that releases all the resources
1557 * allocated by the given job. This job is the argument provided to
1558 * OrthancPluginCreateJob().
1559 *
1560 * @param job The job of interest.
1561 * @ingroup Toolbox
1562 **/
1563 typedef void (*OrthancPluginJobFinalize) (void* job);
1564
1565
1566 /**
1567 * @brief Callback to check the progress of one custom job.
1568 *
1569 * Signature of a callback function that returns the progress of the
1570 * job.
1571 *
1572 * @param job The job of interest.
1573 * @return The progress, as a floating-point number ranging from 0 to 1.
1574 * @ingroup Toolbox
1575 **/
1576 typedef float (*OrthancPluginJobGetProgress) (void* job);
1577
1578
1579 /**
1580 * @brief Callback to retrieve the content of one custom job.
1581 *
1582 * Signature of a callback function that returns human-readable
1583 * statistics about the job. This statistics must be formatted as a
1584 * JSON object. This information is notably displayed in the "Jobs"
1585 * tab of "Orthanc Explorer".
1586 *
1587 * @param job The job of interest.
1588 * @return The statistics, as a JSON object encoded as a string.
1589 * @ingroup Toolbox
1590 **/
1591 typedef const char* (*OrthancPluginJobGetContent) (void* job);
1592
1593
1594 /**
1595 * @brief Callback to serialize one custom job.
1596 *
1597 * Signature of a callback function that returns a serialized
1598 * version of the job, formatted as a JSON object. This
1599 * serialization is stored in the Orthanc database, and is used to
1600 * reload the job on the restart of Orthanc. The "unserialization"
1601 * callback (with OrthancPluginJobsUnserializer signature) will
1602 * receive this serialized object.
1603 *
1604 * @param job The job of interest.
1605 * @return The serialized job, as a JSON object encoded as a string.
1606 * @see OrthancPluginRegisterJobsUnserializer()
1607 * @ingroup Toolbox
1608 **/
1609 typedef const char* (*OrthancPluginJobGetSerialized) (void* job);
1610
1611
1612 /**
1613 * @brief Callback to execute one step of a custom job.
1614 *
1615 * Signature of a callback function that executes one step in the
1616 * job. The jobs engine of Orthanc will make successive calls to
1617 * this method, as long as it returns
1618 * OrthancPluginJobStepStatus_Continue.
1619 *
1620 * @param job The job of interest.
1621 * @return The status of execution.
1622 * @ingroup Toolbox
1623 **/
1624 typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job);
1625
1626
1627 /**
1628 * @brief Callback executed once one custom job leaves the "running" state.
1629 *
1630 * Signature of a callback function that is invoked once a job
1631 * leaves the "running" state. This can happen if the previous call
1632 * to OrthancPluginJobStep has failed/succeeded, if the host Orthanc
1633 * server is being stopped, or if the user manually tags the job as
1634 * paused/canceled. This callback allows the plugin to free
1635 * resources allocated for running this custom job (e.g. to stop
1636 * threads, or to remove temporary files).
1637 *
1638 * Note that handling pauses might involves a specific treatment
1639 * (such a stopping threads, but keeping temporary files on the
1640 * disk). This "paused" situation can be checked by looking at the
1641 * "reason" parameter.
1642 *
1643 * @param job The job of interest.
1644 * @param reason The reason for leaving the "running" state.
1645 * @return 0 if success, or the error code if failure.
1646 * @ingroup Toolbox
1647 **/
1648 typedef OrthancPluginErrorCode (*OrthancPluginJobStop) (void* job,
1649 OrthancPluginJobStopReason reason);
1650
1651
1652 /**
1653 * @brief Callback executed once one stopped custom job is started again.
1654 *
1655 * Signature of a callback function that is invoked once a job
1656 * leaves the "failure/canceled" state, to be started again. This
1657 * function will typically reset the progress to zero. Note that
1658 * before being actually executed, the job would first be tagged as
1659 * "pending" in the Orthanc jobs engine.
1660 *
1661 * @param job The job of interest.
1662 * @return 0 if success, or the error code if failure.
1663 * @ingroup Toolbox
1664 **/
1665 typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job);
1666
1667
1668 /**
1669 * @brief Callback executed to unserialize a custom job.
1670 *
1671 * Signature of a callback function that unserializes a job that was
1672 * saved in the Orthanc database.
1673 *
1674 * @param jobType The type of the job, as provided to OrthancPluginCreateJob().
1675 * @param serialized The serialization of the job, as provided by OrthancPluginJobGetSerialized.
1676 * @return The unserialized job (as created by OrthancPluginCreateJob()), or NULL
1677 * if this unserializer cannot handle this job type.
1678 * @see OrthancPluginRegisterJobsUnserializer()
1679 * @ingroup Callbacks
1680 **/
1681 typedef OrthancPluginJob* (*OrthancPluginJobsUnserializer) (const char* jobType,
1682 const char* serialized);
1683
1684
1685
1686 /**
1687 * @brief Callback executed to update the metrics of the plugin.
1688 *
1689 * Signature of a callback function that is called by Orthanc
1690 * whenever a monitoring tool (such as Prometheus) asks the current
1691 * values of the metrics. This callback gives the plugin a chance to
1692 * update its metrics, by calling OrthancPluginSetMetricsValue().
1693 * This is typically useful for metrics that are expensive to
1694 * acquire.
1695 *
1696 * @see OrthancPluginRegisterRefreshMetrics()
1697 * @ingroup Callbacks
1698 **/
1699 typedef void (*OrthancPluginRefreshMetricsCallback) ();
1700
1701
1702
1703 /**
1704 * @brief Callback executed to encode a binary tag in DICOMweb.
1705 *
1706 * Signature of a callback function that is called by Orthanc
1707 * whenever a DICOM tag that contains a binary value must be written
1708 * to a JSON or XML node, while a DICOMweb document is being
1709 * generated. The value representation (VR) of the DICOM tag can be
1710 * OB, OD, OF, OL, OW, or UN.
1711 *
1712 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1713 * @param node The node being generated, as provided by Orthanc.
1714 * @param setter The setter to be used to encode the content of the node. If
1715 * the setter is not called, the binary tag is not written to the output document.
1716 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1717 * This parameter gives the number of elements in the "levelTagGroup",
1718 * "levelTagElement", and "levelIndex" arrays.
1719 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1720 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1721 * @param levelIndex The index of the node in the parent sequences of the hierarchy.
1722 * @param tagGroup The group of the DICOM tag of interest.
1723 * @param tagElement The element of the DICOM tag of interest.
1724 * @param vr The value representation of the binary DICOM node.
1725 * @ingroup Callbacks
1726 **/
1727 typedef void (*OrthancPluginDicomWebBinaryCallback) (
1728 OrthancPluginDicomWebNode* node,
1729 OrthancPluginDicomWebSetBinaryNode setter,
1730 uint32_t levelDepth,
1731 const uint16_t* levelTagGroup,
1732 const uint16_t* levelTagElement,
1733 const uint32_t* levelIndex,
1734 uint16_t tagGroup,
1735 uint16_t tagElement,
1736 OrthancPluginValueRepresentation vr);
1737
1738
1739
1740 /**
1741 * @brief Callback executed to encode a binary tag in DICOMweb.
1742 *
1743 * Signature of a callback function that is called by Orthanc
1744 * whenever a DICOM tag that contains a binary value must be written
1745 * to a JSON or XML node, while a DICOMweb document is being
1746 * generated. The value representation (VR) of the DICOM tag can be
1747 * OB, OD, OF, OL, OW, or UN.
1748 *
1749 * @see OrthancPluginEncodeDicomWebJson() and OrthancPluginEncodeDicomWebXml()
1750 * @param node The node being generated, as provided by Orthanc.
1751 * @param setter The setter to be used to encode the content of the node. If
1752 * the setter is not called, the binary tag is not written to the output document.
1753 * @param levelDepth The depth of the node in the DICOM hierarchy of sequences.
1754 * This parameter gives the number of elements in the "levelTagGroup",
1755 * "levelTagElement", and "levelIndex" arrays.
1756 * @param levelTagGroup The group of the parent DICOM tags in the hierarchy.
1757 * @param levelTagElement The element of the parent DICOM tags in the hierarchy.
1758 * @param levelIndex The index of the node in the parent sequences of the hierarchy.
1759 * @param tagGroup The group of the DICOM tag of interest.
1760 * @param tagElement The element of the DICOM tag of interest.
1761 * @param vr The value representation of the binary DICOM node.
1762 * @param payload The user payload.
1763 * @ingroup Callbacks
1764 **/
1765 typedef void (*OrthancPluginDicomWebBinaryCallback2) (
1766 OrthancPluginDicomWebNode* node,
1767 OrthancPluginDicomWebSetBinaryNode setter,
1768 uint32_t levelDepth,
1769 const uint16_t* levelTagGroup,
1770 const uint16_t* levelTagElement,
1771 const uint32_t* levelIndex,
1772 uint16_t tagGroup,
1773 uint16_t tagElement,
1774 OrthancPluginValueRepresentation vr,
1775 void* payload);
1776
1777
1778
1779 /**
1780 * @brief Data structure that contains information about the Orthanc core.
1781 **/
1782 typedef struct _OrthancPluginContext_t
1783 {
1784 void* pluginsManager;
1785 const char* orthancVersion;
1786 OrthancPluginFree Free;
1787 OrthancPluginErrorCode (*InvokeService) (struct _OrthancPluginContext_t* context,
1788 _OrthancPluginService service,
1789 const void* params);
1790 } OrthancPluginContext;
1791
1792
1793
1794 /**
1795 * @brief An entry in the dictionary of DICOM tags.
1796 **/
1797 typedef struct
1798 {
1799 uint16_t group; /*!< The group of the tag */
1800 uint16_t element; /*!< The element of the tag */
1801 OrthancPluginValueRepresentation vr; /*!< The value representation of the tag */
1802 uint32_t minMultiplicity; /*!< The minimum multiplicity of the tag */
1803 uint32_t maxMultiplicity; /*!< The maximum multiplicity of the tag (0 means arbitrary) */
1804 } OrthancPluginDictionaryEntry;
1805
1806
1807
1808 /**
1809 * @brief Free a string.
1810 *
1811 * Free a string that was allocated by the core system of Orthanc.
1812 *
1813 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1814 * @param str The string to be freed.
1815 **/
1816 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeString(
1817 OrthancPluginContext* context,
1818 char* str)
1819 {
1820 if (str != NULL)
1821 {
1822 context->Free(str);
1823 }
1824 }
1825
1826
1827 /**
1828 * @brief Check that the version of the hosting Orthanc is above a given version.
1829 *
1830 * This function checks whether the version of the Orthanc server
1831 * running this plugin, is above the given version. Contrarily to
1832 * OrthancPluginCheckVersion(), it is up to the developer of the
1833 * plugin to make sure that all the Orthanc SDK services called by
1834 * the plugin are actually implemented in the given version of
1835 * Orthanc.
1836 *
1837 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1838 * @param expectedMajor Expected major version.
1839 * @param expectedMinor Expected minor version.
1840 * @param expectedRevision Expected revision.
1841 * @return 1 if and only if the versions are compatible. If the
1842 * result is 0, the initialization of the plugin should fail.
1843 * @see OrthancPluginCheckVersion
1844 * @ingroup Callbacks
1845 **/
1846 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginCheckVersionAdvanced(
1847 OrthancPluginContext* context,
1848 int32_t expectedMajor,
1849 int32_t expectedMinor,
1850 int32_t expectedRevision)
1851 {
1852 int32_t major, minor, revision;
1853
1854 if (sizeof(int) != sizeof(int32_t) || /* Ensure binary compatibility with Orthanc SDK <= 1.12.1 */
1855 sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
1856 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
1857 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
1858 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
1859 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
1860 sizeof(int32_t) != sizeof(OrthancPluginContentType) ||
1861 sizeof(int32_t) != sizeof(OrthancPluginResourceType) ||
1862 sizeof(int32_t) != sizeof(OrthancPluginChangeType) ||
1863 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
1864 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) ||
1865 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
1866 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
1867 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
1868 sizeof(int32_t) != sizeof(OrthancPluginCreateDicomFlags) ||
1869 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
1870 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
1871 sizeof(int32_t) != sizeof(OrthancPluginJobStepStatus) ||
1872 sizeof(int32_t) != sizeof(OrthancPluginConstraintType) ||
1873 sizeof(int32_t) != sizeof(OrthancPluginMetricsType) ||
1874 sizeof(int32_t) != sizeof(OrthancPluginDicomWebBinaryMode) ||
1875 sizeof(int32_t) != sizeof(OrthancPluginStorageCommitmentFailureReason) ||
1876 sizeof(int32_t) != sizeof(OrthancPluginReceivedInstanceAction))
1877 {
1878 /* Mismatch in the size of the enumerations */
1879 return 0;
1880 }
1881
1882 /* Assume compatibility with the mainline */
1883 if (!strcmp(context->orthancVersion, "mainline"))
1884 {
1885 return 1;
1886 }
1887
1888 /* Parse the version of the Orthanc core */
1889 if (
1890 #ifdef _MSC_VER
1891 sscanf_s
1892 #else
1893 sscanf
1894 #endif
1895 (context->orthancVersion, "%4d.%4d.%4d", &major, &minor, &revision) != 3)
1896 {
1897 return 0;
1898 }
1899
1900 /* Check the major number of the version */
1901
1902 if (major > expectedMajor)
1903 {
1904 return 1;
1905 }
1906
1907 if (major < expectedMajor)
1908 {
1909 return 0;
1910 }
1911
1912 /* Check the minor number of the version */
1913
1914 if (minor > expectedMinor)
1915 {
1916 return 1;
1917 }
1918
1919 if (minor < expectedMinor)
1920 {
1921 return 0;
1922 }
1923
1924 /* Check the revision number of the version */
1925
1926 if (revision >= expectedRevision)
1927 {
1928 return 1;
1929 }
1930 else
1931 {
1932 return 0;
1933 }
1934 }
1935
1936
1937 /**
1938 * @brief Check the compatibility of the plugin wrt. the version of its hosting Orthanc.
1939 *
1940 * This function checks whether the version of the Orthanc server
1941 * running this plugin, is above the version of the current Orthanc
1942 * SDK header. This guarantees that the plugin is compatible with
1943 * the hosting Orthanc (i.e. it will not call unavailable services).
1944 * The result of this function should always be checked in the
1945 * OrthancPluginInitialize() entry point of the plugin.
1946 *
1947 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1948 * @return 1 if and only if the versions are compatible. If the
1949 * result is 0, the initialization of the plugin should fail.
1950 * @see OrthancPluginCheckVersionAdvanced
1951 * @ingroup Callbacks
1952 **/
1953 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginCheckVersion(
1954 OrthancPluginContext* context)
1955 {
1956 return OrthancPluginCheckVersionAdvanced(
1957 context,
1958 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1959 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
1960 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1961 }
1962
1963
1964 /**
1965 * @brief Free a memory buffer.
1966 *
1967 * Free a memory buffer that was allocated by the core system of Orthanc.
1968 *
1969 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1970 * @param buffer The memory buffer to release.
1971 **/
1972 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer(
1973 OrthancPluginContext* context,
1974 OrthancPluginMemoryBuffer* buffer)
1975 {
1976 context->Free(buffer->data);
1977 }
1978
1979
1980 /**
1981 * @brief Free a memory buffer.
1982 *
1983 * Free a memory buffer that was allocated by the core system of Orthanc.
1984 *
1985 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
1986 * @param buffer The memory buffer to release.
1987 **/
1988 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeMemoryBuffer64(
1989 OrthancPluginContext* context,
1990 OrthancPluginMemoryBuffer64* buffer)
1991 {
1992 context->Free(buffer->data);
1993 }
1994
1995
1996 /**
1997 * @brief Log an error.
1998 *
1999 * Log an error message using the Orthanc logging system.
2000 *
2001 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2002 * @param message The message to be logged.
2003 **/
2004 ORTHANC_PLUGIN_INLINE void OrthancPluginLogError(
2005 OrthancPluginContext* context,
2006 const char* message)
2007 {
2008 context->InvokeService(context, _OrthancPluginService_LogError, message);
2009 }
2010
2011
2012 /**
2013 * @brief Log a warning.
2014 *
2015 * Log a warning message using the Orthanc logging system.
2016 *
2017 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2018 * @param message The message to be logged.
2019 **/
2020 ORTHANC_PLUGIN_INLINE void OrthancPluginLogWarning(
2021 OrthancPluginContext* context,
2022 const char* message)
2023 {
2024 context->InvokeService(context, _OrthancPluginService_LogWarning, message);
2025 }
2026
2027
2028 /**
2029 * @brief Log an information.
2030 *
2031 * Log an information message using the Orthanc logging system.
2032 *
2033 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2034 * @param message The message to be logged.
2035 **/
2036 ORTHANC_PLUGIN_INLINE void OrthancPluginLogInfo(
2037 OrthancPluginContext* context,
2038 const char* message)
2039 {
2040 context->InvokeService(context, _OrthancPluginService_LogInfo, message);
2041 }
2042
2043
2044
2045 typedef struct
2046 {
2047 const char* pathRegularExpression;
2048 OrthancPluginRestCallback callback;
2049 } _OrthancPluginRestCallback;
2050
2051 /**
2052 * @brief Register a REST callback.
2053 *
2054 * This function registers a REST callback against a regular
2055 * expression for a URI. This function must be called during the
2056 * initialization of the plugin, i.e. inside the
2057 * OrthancPluginInitialize() public function.
2058 *
2059 * Each REST callback is guaranteed to run in mutual exclusion.
2060 *
2061 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2062 * @param pathRegularExpression Regular expression for the URI. May contain groups.
2063 * @param callback The callback function to handle the REST call.
2064 * @see OrthancPluginRegisterRestCallbackNoLock()
2065 *
2066 * @note
2067 * The regular expression is case sensitive and must follow the
2068 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
2069 *
2070 * @ingroup Callbacks
2071 **/
2072 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallback(
2073 OrthancPluginContext* context,
2074 const char* pathRegularExpression,
2075 OrthancPluginRestCallback callback)
2076 {
2077 _OrthancPluginRestCallback params;
2078 params.pathRegularExpression = pathRegularExpression;
2079 params.callback = callback;
2080 context->InvokeService(context, _OrthancPluginService_RegisterRestCallback, &params);
2081 }
2082
2083
2084
2085 /**
2086 * @brief Register a REST callback, without locking.
2087 *
2088 * This function registers a REST callback against a regular
2089 * expression for a URI. This function must be called during the
2090 * initialization of the plugin, i.e. inside the
2091 * OrthancPluginInitialize() public function.
2092 *
2093 * Contrarily to OrthancPluginRegisterRestCallback(), the callback
2094 * will NOT be invoked in mutual exclusion. This can be useful for
2095 * high-performance plugins that must handle concurrent requests
2096 * (Orthanc uses a pool of threads, one thread being assigned to
2097 * each incoming HTTP request). Of course, if using this function,
2098 * it is up to the plugin to implement the required locking
2099 * mechanisms.
2100 *
2101 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2102 * @param pathRegularExpression Regular expression for the URI. May contain groups.
2103 * @param callback The callback function to handle the REST call.
2104 * @see OrthancPluginRegisterRestCallback()
2105 *
2106 * @note
2107 * The regular expression is case sensitive and must follow the
2108 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
2109 *
2110 * @ingroup Callbacks
2111 **/
2112 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRestCallbackNoLock(
2113 OrthancPluginContext* context,
2114 const char* pathRegularExpression,
2115 OrthancPluginRestCallback callback)
2116 {
2117 _OrthancPluginRestCallback params;
2118 params.pathRegularExpression = pathRegularExpression;
2119 params.callback = callback;
2120 context->InvokeService(context, _OrthancPluginService_RegisterRestCallbackNoLock, &params);
2121 }
2122
2123
2124
2125 typedef struct
2126 {
2127 OrthancPluginOnStoredInstanceCallback callback;
2128 } _OrthancPluginOnStoredInstanceCallback;
2129
2130 /**
2131 * @brief Register a callback for received instances.
2132 *
2133 * This function registers a callback function that is called
2134 * whenever a new DICOM instance is stored into the Orthanc core.
2135 *
2136 * @warning Your callback function will be called synchronously with
2137 * the core of Orthanc. This implies that deadlocks might emerge if
2138 * you call other core primitives of Orthanc in your callback (such
2139 * deadlocks are particularly visible in the presence of other plugins
2140 * or Lua scripts). It is thus strongly advised to avoid any call to
2141 * the REST API of Orthanc in the callback. If you have to call
2142 * other primitives of Orthanc, you should make these calls in a
2143 * separate thread, passing the pending events to be processed
2144 * through a message queue.
2145 *
2146 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2147 * @param callback The callback function.
2148 * @ingroup Callbacks
2149 **/
2150 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnStoredInstanceCallback(
2151 OrthancPluginContext* context,
2152 OrthancPluginOnStoredInstanceCallback callback)
2153 {
2154 _OrthancPluginOnStoredInstanceCallback params;
2155 params.callback = callback;
2156
2157 context->InvokeService(context, _OrthancPluginService_RegisterOnStoredInstanceCallback, &params);
2158 }
2159
2160
2161
2162 typedef struct
2163 {
2164 OrthancPluginRestOutput* output;
2165 const void* answer;
2166 uint32_t answerSize;
2167 const char* mimeType;
2168 } _OrthancPluginAnswerBuffer;
2169
2170 /**
2171 * @brief Answer to a REST request.
2172 *
2173 * This function answers to a REST request with the content of a memory buffer.
2174 *
2175 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2176 * @param output The HTTP connection to the client application.
2177 * @param answer Pointer to the memory buffer containing the answer.
2178 * @param answerSize Number of bytes of the answer.
2179 * @param mimeType The MIME type of the answer.
2180 * @ingroup REST
2181 **/
2182 ORTHANC_PLUGIN_INLINE void OrthancPluginAnswerBuffer(
2183 OrthancPluginContext* context,
2184 OrthancPluginRestOutput* output,
2185 const void* answer,
2186 uint32_t answerSize,
2187 const char* mimeType)
2188 {
2189 _OrthancPluginAnswerBuffer params;
2190 params.output = output;
2191 params.answer = answer;
2192 params.answerSize = answerSize;
2193 params.mimeType = mimeType;
2194 context->InvokeService(context, _OrthancPluginService_AnswerBuffer, &params);
2195 }
2196
2197
2198 typedef struct
2199 {
2200 OrthancPluginRestOutput* output;
2201 OrthancPluginPixelFormat format;
2202 uint32_t width;
2203 uint32_t height;
2204 uint32_t pitch;
2205 const void* buffer;
2206 } _OrthancPluginCompressAndAnswerPngImage;
2207
2208 typedef struct
2209 {
2210 OrthancPluginRestOutput* output;
2211 OrthancPluginImageFormat imageFormat;
2212 OrthancPluginPixelFormat pixelFormat;
2213 uint32_t width;
2214 uint32_t height;
2215 uint32_t pitch;
2216 const void* buffer;
2217 uint8_t quality;
2218 } _OrthancPluginCompressAndAnswerImage;
2219
2220
2221 /**
2222 * @brief Answer to a REST request with a PNG image.
2223 *
2224 * This function answers to a REST request with a PNG image. The
2225 * parameters of this function describe a memory buffer that
2226 * contains an uncompressed image. The image will be automatically compressed
2227 * as a PNG image by the core system of Orthanc.
2228 *
2229 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2230 * @param output The HTTP connection to the client application.
2231 * @param format The memory layout of the uncompressed image.
2232 * @param width The width of the image.
2233 * @param height The height of the image.
2234 * @param pitch The pitch of the image (i.e. the number of bytes
2235 * between 2 successive lines of the image in the memory buffer).
2236 * @param buffer The memory buffer containing the uncompressed image.
2237 * @ingroup REST
2238 **/
2239 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerPngImage(
2240 OrthancPluginContext* context,
2241 OrthancPluginRestOutput* output,
2242 OrthancPluginPixelFormat format,
2243 uint32_t width,
2244 uint32_t height,
2245 uint32_t pitch,
2246 const void* buffer)
2247 {
2248 _OrthancPluginCompressAndAnswerImage params;
2249 params.output = output;
2250 params.imageFormat = OrthancPluginImageFormat_Png;
2251 params.pixelFormat = format;
2252 params.width = width;
2253 params.height = height;
2254 params.pitch = pitch;
2255 params.buffer = buffer;
2256 params.quality = 0; /* No quality for PNG */
2257 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
2258 }
2259
2260
2261
2262 typedef struct
2263 {
2264 OrthancPluginMemoryBuffer* target;
2265 const char* instanceId;
2266 } _OrthancPluginGetDicomForInstance;
2267
2268 /**
2269 * @brief Retrieve a DICOM instance using its Orthanc identifier.
2270 *
2271 * Retrieve a DICOM instance using its Orthanc identifier. The DICOM
2272 * file is stored into a newly allocated memory buffer.
2273 *
2274 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2275 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2276 * @param instanceId The Orthanc identifier of the DICOM instance of interest.
2277 * @return 0 if success, or the error code if failure.
2278 * @ingroup Orthanc
2279 **/
2280 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetDicomForInstance(
2281 OrthancPluginContext* context,
2282 OrthancPluginMemoryBuffer* target,
2283 const char* instanceId)
2284 {
2285 _OrthancPluginGetDicomForInstance params;
2286 params.target = target;
2287 params.instanceId = instanceId;
2288 return context->InvokeService(context, _OrthancPluginService_GetDicomForInstance, &params);
2289 }
2290
2291
2292
2293 typedef struct
2294 {
2295 OrthancPluginMemoryBuffer* target;
2296 const char* uri;
2297 } _OrthancPluginRestApiGet;
2298
2299 /**
2300 * @brief Make a GET call to the built-in Orthanc REST API.
2301 *
2302 * Make a GET call to the built-in Orthanc REST API. The result to
2303 * the query is stored into a newly allocated memory buffer.
2304 *
2305 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2306 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2307 * @param uri The URI in the built-in Orthanc API.
2308 * @return 0 if success, or the error code if failure.
2309 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2310 * @see OrthancPluginRestApiGetAfterPlugins
2311 * @ingroup Orthanc
2312 **/
2313 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet(
2314 OrthancPluginContext* context,
2315 OrthancPluginMemoryBuffer* target,
2316 const char* uri)
2317 {
2318 _OrthancPluginRestApiGet params;
2319 params.target = target;
2320 params.uri = uri;
2321 return context->InvokeService(context, _OrthancPluginService_RestApiGet, &params);
2322 }
2323
2324
2325
2326 /**
2327 * @brief Make a GET call to the REST API, as tainted by the plugins.
2328 *
2329 * Make a GET call to the Orthanc REST API, after all the plugins
2330 * are applied. In other words, if some plugin overrides or adds the
2331 * called URI to the built-in Orthanc REST API, this call will
2332 * return the result provided by this plugin. The result to the
2333 * query is stored into a newly allocated memory buffer.
2334 *
2335 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2336 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2337 * @param uri The URI in the built-in Orthanc API.
2338 * @return 0 if success, or the error code if failure.
2339 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2340 * @see OrthancPluginRestApiGet
2341 * @ingroup Orthanc
2342 **/
2343 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGetAfterPlugins(
2344 OrthancPluginContext* context,
2345 OrthancPluginMemoryBuffer* target,
2346 const char* uri)
2347 {
2348 _OrthancPluginRestApiGet params;
2349 params.target = target;
2350 params.uri = uri;
2351 return context->InvokeService(context, _OrthancPluginService_RestApiGetAfterPlugins, &params);
2352 }
2353
2354
2355
2356 typedef struct
2357 {
2358 OrthancPluginMemoryBuffer* target;
2359 const char* uri;
2360 const void* body;
2361 uint32_t bodySize;
2362 } _OrthancPluginRestApiPostPut;
2363
2364 /**
2365 * @brief Make a POST call to the built-in Orthanc REST API.
2366 *
2367 * Make a POST call to the built-in Orthanc REST API. The result to
2368 * the query is stored into a newly allocated memory buffer.
2369 *
2370 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2371 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2372 * @param uri The URI in the built-in Orthanc API.
2373 * @param body The body of the POST request.
2374 * @param bodySize The size of the body.
2375 * @return 0 if success, or the error code if failure.
2376 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2377 * @see OrthancPluginRestApiPostAfterPlugins
2378 * @ingroup Orthanc
2379 **/
2380 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPost(
2381 OrthancPluginContext* context,
2382 OrthancPluginMemoryBuffer* target,
2383 const char* uri,
2384 const void* body,
2385 uint32_t bodySize)
2386 {
2387 _OrthancPluginRestApiPostPut params;
2388 params.target = target;
2389 params.uri = uri;
2390 params.body = body;
2391 params.bodySize = bodySize;
2392 return context->InvokeService(context, _OrthancPluginService_RestApiPost, &params);
2393 }
2394
2395
2396 /**
2397 * @brief Make a POST call to the REST API, as tainted by the plugins.
2398 *
2399 * Make a POST call to the Orthanc REST API, after all the plugins
2400 * are applied. In other words, if some plugin overrides or adds the
2401 * called URI to the built-in Orthanc REST API, this call will
2402 * return the result provided by this plugin. The result to the
2403 * query is stored into a newly allocated memory buffer.
2404 *
2405 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2406 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2407 * @param uri The URI in the built-in Orthanc API.
2408 * @param body The body of the POST request.
2409 * @param bodySize The size of the body.
2410 * @return 0 if success, or the error code if failure.
2411 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2412 * @see OrthancPluginRestApiPost
2413 * @ingroup Orthanc
2414 **/
2415 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPostAfterPlugins(
2416 OrthancPluginContext* context,
2417 OrthancPluginMemoryBuffer* target,
2418 const char* uri,
2419 const void* body,
2420 uint32_t bodySize)
2421 {
2422 _OrthancPluginRestApiPostPut params;
2423 params.target = target;
2424 params.uri = uri;
2425 params.body = body;
2426 params.bodySize = bodySize;
2427 return context->InvokeService(context, _OrthancPluginService_RestApiPostAfterPlugins, &params);
2428 }
2429
2430
2431
2432 /**
2433 * @brief Make a DELETE call to the built-in Orthanc REST API.
2434 *
2435 * Make a DELETE call to the built-in Orthanc REST API.
2436 *
2437 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2438 * @param uri The URI to delete in the built-in Orthanc API.
2439 * @return 0 if success, or the error code if failure.
2440 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2441 * @see OrthancPluginRestApiDeleteAfterPlugins
2442 * @ingroup Orthanc
2443 **/
2444 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDelete(
2445 OrthancPluginContext* context,
2446 const char* uri)
2447 {
2448 return context->InvokeService(context, _OrthancPluginService_RestApiDelete, uri);
2449 }
2450
2451
2452 /**
2453 * @brief Make a DELETE call to the REST API, as tainted by the plugins.
2454 *
2455 * Make a DELETE call to the Orthanc REST API, after all the plugins
2456 * are applied. In other words, if some plugin overrides or adds the
2457 * called URI to the built-in Orthanc REST API, this call will
2458 * return the result provided by this plugin.
2459 *
2460 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2461 * @param uri The URI to delete in the built-in Orthanc API.
2462 * @return 0 if success, or the error code if failure.
2463 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2464 * @see OrthancPluginRestApiDelete
2465 * @ingroup Orthanc
2466 **/
2467 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiDeleteAfterPlugins(
2468 OrthancPluginContext* context,
2469 const char* uri)
2470 {
2471 return context->InvokeService(context, _OrthancPluginService_RestApiDeleteAfterPlugins, uri);
2472 }
2473
2474
2475
2476 /**
2477 * @brief Make a PUT call to the built-in Orthanc REST API.
2478 *
2479 * Make a PUT call to the built-in Orthanc REST API. The result to
2480 * the query is stored into a newly allocated memory buffer.
2481 *
2482 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2483 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2484 * @param uri The URI in the built-in Orthanc API.
2485 * @param body The body of the PUT request.
2486 * @param bodySize The size of the body.
2487 * @return 0 if success, or the error code if failure.
2488 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2489 * @see OrthancPluginRestApiPutAfterPlugins
2490 * @ingroup Orthanc
2491 **/
2492 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPut(
2493 OrthancPluginContext* context,
2494 OrthancPluginMemoryBuffer* target,
2495 const char* uri,
2496 const void* body,
2497 uint32_t bodySize)
2498 {
2499 _OrthancPluginRestApiPostPut params;
2500 params.target = target;
2501 params.uri = uri;
2502 params.body = body;
2503 params.bodySize = bodySize;
2504 return context->InvokeService(context, _OrthancPluginService_RestApiPut, &params);
2505 }
2506
2507
2508
2509 /**
2510 * @brief Make a PUT call to the REST API, as tainted by the plugins.
2511 *
2512 * Make a PUT call to the Orthanc REST API, after all the plugins
2513 * are applied. In other words, if some plugin overrides or adds the
2514 * called URI to the built-in Orthanc REST API, this call will
2515 * return the result provided by this plugin. The result to the
2516 * query is stored into a newly allocated memory buffer.
2517 *
2518 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2519 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
2520 * @param uri The URI in the built-in Orthanc API.
2521 * @param body The body of the PUT request.
2522 * @param bodySize The size of the body.
2523 * @return 0 if success, or the error code if failure.
2524 * @note If the resource is not existing (error 404), the error code will be OrthancPluginErrorCode_UnknownResource.
2525 * @see OrthancPluginRestApiPut
2526 * @ingroup Orthanc
2527 **/
2528 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiPutAfterPlugins(
2529 OrthancPluginContext* context,
2530 OrthancPluginMemoryBuffer* target,
2531 const char* uri,
2532 const void* body,
2533 uint32_t bodySize)
2534 {
2535 _OrthancPluginRestApiPostPut params;
2536 params.target = target;
2537 params.uri = uri;
2538 params.body = body;
2539 params.bodySize = bodySize;
2540 return context->InvokeService(context, _OrthancPluginService_RestApiPutAfterPlugins, &params);
2541 }
2542
2543
2544
2545 typedef struct
2546 {
2547 OrthancPluginRestOutput* output;
2548 const char* argument;
2549 } _OrthancPluginOutputPlusArgument;
2550
2551 /**
2552 * @brief Redirect a REST request.
2553 *
2554 * This function answers to a REST request by redirecting the user
2555 * to another URI using HTTP status 301.
2556 *
2557 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2558 * @param output The HTTP connection to the client application.
2559 * @param redirection Where to redirect.
2560 * @ingroup REST
2561 **/
2562 ORTHANC_PLUGIN_INLINE void OrthancPluginRedirect(
2563 OrthancPluginContext* context,
2564 OrthancPluginRestOutput* output,
2565 const char* redirection)
2566 {
2567 _OrthancPluginOutputPlusArgument params;
2568 params.output = output;
2569 params.argument = redirection;
2570 context->InvokeService(context, _OrthancPluginService_Redirect, &params);
2571 }
2572
2573
2574
2575 typedef struct
2576 {
2577 char** result;
2578 const char* argument;
2579 } _OrthancPluginRetrieveDynamicString;
2580
2581 /**
2582 * @brief Look for a patient.
2583 *
2584 * Look for a patient stored in Orthanc, using its Patient ID tag (0x0010, 0x0020).
2585 * This function uses the database index to run as fast as possible (it does not loop
2586 * over all the stored patients).
2587 *
2588 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2589 * @param patientID The Patient ID of interest.
2590 * @return The NULL value if the patient is non-existent, or a string containing the
2591 * Orthanc ID of the patient. This string must be freed by OrthancPluginFreeString().
2592 * @ingroup Orthanc
2593 **/
2594 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupPatient(
2595 OrthancPluginContext* context,
2596 const char* patientID)
2597 {
2598 char* result;
2599
2600 _OrthancPluginRetrieveDynamicString params;
2601 params.result = &result;
2602 params.argument = patientID;
2603
2604 if (context->InvokeService(context, _OrthancPluginService_LookupPatient, &params) != OrthancPluginErrorCode_Success)
2605 {
2606 /* Error */
2607 return NULL;
2608 }
2609 else
2610 {
2611 return result;
2612 }
2613 }
2614
2615
2616 /**
2617 * @brief Look for a study.
2618 *
2619 * Look for a study stored in Orthanc, using its Study Instance UID tag (0x0020, 0x000d).
2620 * This function uses the database index to run as fast as possible (it does not loop
2621 * over all the stored studies).
2622 *
2623 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2624 * @param studyUID The Study Instance UID of interest.
2625 * @return The NULL value if the study is non-existent, or a string containing the
2626 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2627 * @ingroup Orthanc
2628 **/
2629 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudy(
2630 OrthancPluginContext* context,
2631 const char* studyUID)
2632 {
2633 char* result;
2634
2635 _OrthancPluginRetrieveDynamicString params;
2636 params.result = &result;
2637 params.argument = studyUID;
2638
2639 if (context->InvokeService(context, _OrthancPluginService_LookupStudy, &params) != OrthancPluginErrorCode_Success)
2640 {
2641 /* Error */
2642 return NULL;
2643 }
2644 else
2645 {
2646 return result;
2647 }
2648 }
2649
2650
2651 /**
2652 * @brief Look for a study, using the accession number.
2653 *
2654 * Look for a study stored in Orthanc, using its Accession Number tag (0x0008, 0x0050).
2655 * This function uses the database index to run as fast as possible (it does not loop
2656 * over all the stored studies).
2657 *
2658 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2659 * @param accessionNumber The Accession Number of interest.
2660 * @return The NULL value if the study is non-existent, or a string containing the
2661 * Orthanc ID of the study. This string must be freed by OrthancPluginFreeString().
2662 * @ingroup Orthanc
2663 **/
2664 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupStudyWithAccessionNumber(
2665 OrthancPluginContext* context,
2666 const char* accessionNumber)
2667 {
2668 char* result;
2669
2670 _OrthancPluginRetrieveDynamicString params;
2671 params.result = &result;
2672 params.argument = accessionNumber;
2673
2674 if (context->InvokeService(context, _OrthancPluginService_LookupStudyWithAccessionNumber, &params) != OrthancPluginErrorCode_Success)
2675 {
2676 /* Error */
2677 return NULL;
2678 }
2679 else
2680 {
2681 return result;
2682 }
2683 }
2684
2685
2686 /**
2687 * @brief Look for a series.
2688 *
2689 * Look for a series stored in Orthanc, using its Series Instance UID tag (0x0020, 0x000e).
2690 * This function uses the database index to run as fast as possible (it does not loop
2691 * over all the stored series).
2692 *
2693 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2694 * @param seriesUID The Series Instance UID of interest.
2695 * @return The NULL value if the series is non-existent, or a string containing the
2696 * Orthanc ID of the series. This string must be freed by OrthancPluginFreeString().
2697 * @ingroup Orthanc
2698 **/
2699 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupSeries(
2700 OrthancPluginContext* context,
2701 const char* seriesUID)
2702 {
2703 char* result;
2704
2705 _OrthancPluginRetrieveDynamicString params;
2706 params.result = &result;
2707 params.argument = seriesUID;
2708
2709 if (context->InvokeService(context, _OrthancPluginService_LookupSeries, &params) != OrthancPluginErrorCode_Success)
2710 {
2711 /* Error */
2712 return NULL;
2713 }
2714 else
2715 {
2716 return result;
2717 }
2718 }
2719
2720
2721 /**
2722 * @brief Look for an instance.
2723 *
2724 * Look for an instance stored in Orthanc, using its SOP Instance UID tag (0x0008, 0x0018).
2725 * This function uses the database index to run as fast as possible (it does not loop
2726 * over all the stored instances).
2727 *
2728 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2729 * @param sopInstanceUID The SOP Instance UID of interest.
2730 * @return The NULL value if the instance is non-existent, or a string containing the
2731 * Orthanc ID of the instance. This string must be freed by OrthancPluginFreeString().
2732 * @ingroup Orthanc
2733 **/
2734 ORTHANC_PLUGIN_INLINE char* OrthancPluginLookupInstance(
2735 OrthancPluginContext* context,
2736 const char* sopInstanceUID)
2737 {
2738 char* result;
2739
2740 _OrthancPluginRetrieveDynamicString params;
2741 params.result = &result;
2742 params.argument = sopInstanceUID;
2743
2744 if (context->InvokeService(context, _OrthancPluginService_LookupInstance, &params) != OrthancPluginErrorCode_Success)
2745 {
2746 /* Error */
2747 return NULL;
2748 }
2749 else
2750 {
2751 return result;
2752 }
2753 }
2754
2755
2756
2757 typedef struct
2758 {
2759 OrthancPluginRestOutput* output;
2760 uint16_t status;
2761 } _OrthancPluginSendHttpStatusCode;
2762
2763 /**
2764 * @brief Send a HTTP status code.
2765 *
2766 * This function answers to a REST request by sending a HTTP status
2767 * code (such as "400 - Bad Request"). Note that:
2768 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
2769 * - Redirections (status 301) must use ::OrthancPluginRedirect().
2770 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
2771 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
2772 *
2773 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2774 * @param output The HTTP connection to the client application.
2775 * @param status The HTTP status code to be sent.
2776 * @ingroup REST
2777 * @see OrthancPluginSendHttpStatus()
2778 **/
2779 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatusCode(
2780 OrthancPluginContext* context,
2781 OrthancPluginRestOutput* output,
2782 uint16_t status)
2783 {
2784 _OrthancPluginSendHttpStatusCode params;
2785 params.output = output;
2786 params.status = status;
2787 context->InvokeService(context, _OrthancPluginService_SendHttpStatusCode, &params);
2788 }
2789
2790
2791 /**
2792 * @brief Signal that a REST request is not authorized.
2793 *
2794 * This function answers to a REST request by signaling that it is
2795 * not authorized.
2796 *
2797 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2798 * @param output The HTTP connection to the client application.
2799 * @param realm The realm for the authorization process.
2800 * @ingroup REST
2801 **/
2802 ORTHANC_PLUGIN_INLINE void OrthancPluginSendUnauthorized(
2803 OrthancPluginContext* context,
2804 OrthancPluginRestOutput* output,
2805 const char* realm)
2806 {
2807 _OrthancPluginOutputPlusArgument params;
2808 params.output = output;
2809 params.argument = realm;
2810 context->InvokeService(context, _OrthancPluginService_SendUnauthorized, &params);
2811 }
2812
2813
2814 /**
2815 * @brief Signal that this URI does not support this HTTP method.
2816 *
2817 * This function answers to a REST request by signaling that the
2818 * queried URI does not support this method.
2819 *
2820 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2821 * @param output The HTTP connection to the client application.
2822 * @param allowedMethods The allowed methods for this URI (e.g. "GET,POST" after a PUT or a POST request).
2823 * @ingroup REST
2824 **/
2825 ORTHANC_PLUGIN_INLINE void OrthancPluginSendMethodNotAllowed(
2826 OrthancPluginContext* context,
2827 OrthancPluginRestOutput* output,
2828 const char* allowedMethods)
2829 {
2830 _OrthancPluginOutputPlusArgument params;
2831 params.output = output;
2832 params.argument = allowedMethods;
2833 context->InvokeService(context, _OrthancPluginService_SendMethodNotAllowed, &params);
2834 }
2835
2836
2837 typedef struct
2838 {
2839 OrthancPluginRestOutput* output;
2840 const char* key;
2841 const char* value;
2842 } _OrthancPluginSetHttpHeader;
2843
2844 /**
2845 * @brief Set a cookie.
2846 *
2847 * This function sets a cookie in the HTTP client.
2848 *
2849 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2850 * @param output The HTTP connection to the client application.
2851 * @param cookie The cookie to be set.
2852 * @param value The value of the cookie.
2853 * @ingroup REST
2854 **/
2855 ORTHANC_PLUGIN_INLINE void OrthancPluginSetCookie(
2856 OrthancPluginContext* context,
2857 OrthancPluginRestOutput* output,
2858 const char* cookie,
2859 const char* value)
2860 {
2861 _OrthancPluginSetHttpHeader params;
2862 params.output = output;
2863 params.key = cookie;
2864 params.value = value;
2865 context->InvokeService(context, _OrthancPluginService_SetCookie, &params);
2866 }
2867
2868
2869 /**
2870 * @brief Set some HTTP header.
2871 *
2872 * This function sets a HTTP header in the HTTP answer.
2873 *
2874 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2875 * @param output The HTTP connection to the client application.
2876 * @param key The HTTP header to be set.
2877 * @param value The value of the HTTP header.
2878 * @ingroup REST
2879 **/
2880 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpHeader(
2881 OrthancPluginContext* context,
2882 OrthancPluginRestOutput* output,
2883 const char* key,
2884 const char* value)
2885 {
2886 _OrthancPluginSetHttpHeader params;
2887 params.output = output;
2888 params.key = key;
2889 params.value = value;
2890 context->InvokeService(context, _OrthancPluginService_SetHttpHeader, &params);
2891 }
2892
2893
2894 typedef struct
2895 {
2896 char** resultStringToFree;
2897 const char** resultString;
2898 int64_t* resultInt64;
2899 const char* key;
2900 const OrthancPluginDicomInstance* instance;
2901 OrthancPluginInstanceOrigin* resultOrigin; /* New in Orthanc 0.9.5 SDK */
2902 } _OrthancPluginAccessDicomInstance;
2903
2904
2905 /**
2906 * @brief Get the AET of a DICOM instance.
2907 *
2908 * This function returns the Application Entity Title (AET) of the
2909 * DICOM modality from which a DICOM instance originates.
2910 *
2911 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2912 * @param instance The instance of interest.
2913 * @return The AET if success, NULL if error.
2914 * @ingroup DicomInstance
2915 **/
2916 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceRemoteAet(
2917 OrthancPluginContext* context,
2918 const OrthancPluginDicomInstance* instance)
2919 {
2920 const char* result;
2921
2922 _OrthancPluginAccessDicomInstance params;
2923 memset(&params, 0, sizeof(params));
2924 params.resultString = &result;
2925 params.instance = instance;
2926
2927 if (context->InvokeService(context, _OrthancPluginService_GetInstanceRemoteAet, &params) != OrthancPluginErrorCode_Success)
2928 {
2929 /* Error */
2930 return NULL;
2931 }
2932 else
2933 {
2934 return result;
2935 }
2936 }
2937
2938
2939 /**
2940 * @brief Get the size of a DICOM file.
2941 *
2942 * This function returns the number of bytes of the given DICOM instance.
2943 *
2944 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2945 * @param instance The instance of interest.
2946 * @return The size of the file, -1 in case of error.
2947 * @ingroup DicomInstance
2948 **/
2949 ORTHANC_PLUGIN_INLINE int64_t OrthancPluginGetInstanceSize(
2950 OrthancPluginContext* context,
2951 const OrthancPluginDicomInstance* instance)
2952 {
2953 int64_t size;
2954
2955 _OrthancPluginAccessDicomInstance params;
2956 memset(&params, 0, sizeof(params));
2957 params.resultInt64 = &size;
2958 params.instance = instance;
2959
2960 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSize, &params) != OrthancPluginErrorCode_Success)
2961 {
2962 /* Error */
2963 return -1;
2964 }
2965 else
2966 {
2967 return size;
2968 }
2969 }
2970
2971
2972 /**
2973 * @brief Get the data of a DICOM file.
2974 *
2975 * This function returns a pointer to the content of the given DICOM instance.
2976 *
2977 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
2978 * @param instance The instance of interest.
2979 * @return The pointer to the DICOM data, NULL in case of error.
2980 * @ingroup DicomInstance
2981 **/
2982 ORTHANC_PLUGIN_INLINE const void* OrthancPluginGetInstanceData(
2983 OrthancPluginContext* context,
2984 const OrthancPluginDicomInstance* instance)
2985 {
2986 const char* result;
2987
2988 _OrthancPluginAccessDicomInstance params;
2989 memset(&params, 0, sizeof(params));
2990 params.resultString = &result;
2991 params.instance = instance;
2992
2993 if (context->InvokeService(context, _OrthancPluginService_GetInstanceData, &params) != OrthancPluginErrorCode_Success)
2994 {
2995 /* Error */
2996 return NULL;
2997 }
2998 else
2999 {
3000 return result;
3001 }
3002 }
3003
3004
3005 /**
3006 * @brief Get the DICOM tag hierarchy as a JSON file.
3007 *
3008 * This function returns a pointer to a newly created string
3009 * containing a JSON file. This JSON file encodes the tag hierarchy
3010 * of the given DICOM instance.
3011 *
3012 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3013 * @param instance The instance of interest.
3014 * @return The NULL value in case of error, or a string containing the JSON file.
3015 * This string must be freed by OrthancPluginFreeString().
3016 * @ingroup DicomInstance
3017 **/
3018 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceJson(
3019 OrthancPluginContext* context,
3020 const OrthancPluginDicomInstance* instance)
3021 {
3022 char* result;
3023
3024 _OrthancPluginAccessDicomInstance params;
3025 memset(&params, 0, sizeof(params));
3026 params.resultStringToFree = &result;
3027 params.instance = instance;
3028
3029 if (context->InvokeService(context, _OrthancPluginService_GetInstanceJson, &params) != OrthancPluginErrorCode_Success)
3030 {
3031 /* Error */
3032 return NULL;
3033 }
3034 else
3035 {
3036 return result;
3037 }
3038 }
3039
3040
3041 /**
3042 * @brief Get the DICOM tag hierarchy as a JSON file (with simplification).
3043 *
3044 * This function returns a pointer to a newly created string
3045 * containing a JSON file. This JSON file encodes the tag hierarchy
3046 * of the given DICOM instance. In contrast with
3047 * ::OrthancPluginGetInstanceJson(), the returned JSON file is in
3048 * its simplified version.
3049 *
3050 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3051 * @param instance The instance of interest.
3052 * @return The NULL value in case of error, or a string containing the JSON file.
3053 * This string must be freed by OrthancPluginFreeString().
3054 * @ingroup DicomInstance
3055 **/
3056 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceSimplifiedJson(
3057 OrthancPluginContext* context,
3058 const OrthancPluginDicomInstance* instance)
3059 {
3060 char* result;
3061
3062 _OrthancPluginAccessDicomInstance params;
3063 memset(&params, 0, sizeof(params));
3064 params.resultStringToFree = &result;
3065 params.instance = instance;
3066
3067 if (context->InvokeService(context, _OrthancPluginService_GetInstanceSimplifiedJson, &params) != OrthancPluginErrorCode_Success)
3068 {
3069 /* Error */
3070 return NULL;
3071 }
3072 else
3073 {
3074 return result;
3075 }
3076 }
3077
3078
3079 /**
3080 * @brief Check whether a DICOM instance is associated with some metadata.
3081 *
3082 * This function checks whether the DICOM instance of interest is
3083 * associated with some metadata. As of Orthanc 0.8.1, in the
3084 * callbacks registered by
3085 * ::OrthancPluginRegisterOnStoredInstanceCallback(), the only
3086 * possibly available metadata are "ReceptionDate", "RemoteAET" and
3087 * "IndexInSeries".
3088 *
3089 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3090 * @param instance The instance of interest.
3091 * @param metadata The metadata of interest.
3092 * @return 1 if the metadata is present, 0 if it is absent, -1 in case of error.
3093 * @ingroup DicomInstance
3094 **/
3095 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginHasInstanceMetadata(
3096 OrthancPluginContext* context,
3097 const OrthancPluginDicomInstance* instance,
3098 const char* metadata)
3099 {
3100 int64_t result;
3101
3102 _OrthancPluginAccessDicomInstance params;
3103 memset(&params, 0, sizeof(params));
3104 params.resultInt64 = &result;
3105 params.instance = instance;
3106 params.key = metadata;
3107
3108 if (context->InvokeService(context, _OrthancPluginService_HasInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
3109 {
3110 /* Error */
3111 return -1;
3112 }
3113 else
3114 {
3115 return (result != 0);
3116 }
3117 }
3118
3119
3120 /**
3121 * @brief Get the value of some metadata associated with a given DICOM instance.
3122 *
3123 * This functions returns the value of some metadata that is associated with the DICOM instance of interest.
3124 * Before calling this function, the existence of the metadata must have been checked with
3125 * ::OrthancPluginHasInstanceMetadata().
3126 *
3127 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3128 * @param instance The instance of interest.
3129 * @param metadata The metadata of interest.
3130 * @return The metadata value if success, NULL if error. Please note that the
3131 * returned string belongs to the instance object and must NOT be
3132 * deallocated. Please make a copy of the string if you wish to access
3133 * it later.
3134 * @ingroup DicomInstance
3135 **/
3136 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetInstanceMetadata(
3137 OrthancPluginContext* context,
3138 const OrthancPluginDicomInstance* instance,
3139 const char* metadata)
3140 {
3141 const char* result;
3142
3143 _OrthancPluginAccessDicomInstance params;
3144 memset(&params, 0, sizeof(params));
3145 params.resultString = &result;
3146 params.instance = instance;
3147 params.key = metadata;
3148
3149 if (context->InvokeService(context, _OrthancPluginService_GetInstanceMetadata, &params) != OrthancPluginErrorCode_Success)
3150 {
3151 /* Error */
3152 return NULL;
3153 }
3154 else
3155 {
3156 return result;
3157 }
3158 }
3159
3160
3161
3162 typedef struct
3163 {
3164 OrthancPluginStorageCreate create;
3165 OrthancPluginStorageRead read;
3166 OrthancPluginStorageRemove remove;
3167 OrthancPluginFree free;
3168 } _OrthancPluginRegisterStorageArea;
3169
3170 /**
3171 * @brief Register a custom storage area.
3172 *
3173 * This function registers a custom storage area, to replace the
3174 * built-in way Orthanc stores its files on the filesystem. This
3175 * function must be called during the initialization of the plugin,
3176 * i.e. inside the OrthancPluginInitialize() public function.
3177 *
3178 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3179 * @param create The callback function to store a file on the custom storage area.
3180 * @param read The callback function to read a file from the custom storage area.
3181 * @param remove The callback function to remove a file from the custom storage area.
3182 * @ingroup Callbacks
3183 * @deprecated Please use OrthancPluginRegisterStorageArea2()
3184 **/
3185 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea(
3186 OrthancPluginContext* context,
3187 OrthancPluginStorageCreate create,
3188 OrthancPluginStorageRead read,
3189 OrthancPluginStorageRemove remove)
3190 {
3191 _OrthancPluginRegisterStorageArea params;
3192 params.create = create;
3193 params.read = read;
3194 params.remove = remove;
3195
3196 #ifdef __cplusplus
3197 params.free = ::free;
3198 #else
3199 params.free = free;
3200 #endif
3201
3202 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea, &params);
3203 }
3204
3205
3206
3207 /**
3208 * @brief Return the path to the Orthanc executable.
3209 *
3210 * This function returns the path to the Orthanc executable.
3211 *
3212 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3213 * @return NULL in the case of an error, or a newly allocated string
3214 * containing the path. This string must be freed by
3215 * OrthancPluginFreeString().
3216 **/
3217 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancPath(OrthancPluginContext* context)
3218 {
3219 char* result;
3220
3221 _OrthancPluginRetrieveDynamicString params;
3222 params.result = &result;
3223 params.argument = NULL;
3224
3225 if (context->InvokeService(context, _OrthancPluginService_GetOrthancPath, &params) != OrthancPluginErrorCode_Success)
3226 {
3227 /* Error */
3228 return NULL;
3229 }
3230 else
3231 {
3232 return result;
3233 }
3234 }
3235
3236
3237 /**
3238 * @brief Return the directory containing the Orthanc.
3239 *
3240 * This function returns the path to the directory containing the Orthanc executable.
3241 *
3242 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3243 * @return NULL in the case of an error, or a newly allocated string
3244 * containing the path. This string must be freed by
3245 * OrthancPluginFreeString().
3246 **/
3247 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetOrthancDirectory(OrthancPluginContext* context)
3248 {
3249 char* result;
3250
3251 _OrthancPluginRetrieveDynamicString params;
3252 params.result = &result;
3253 params.argument = NULL;
3254
3255 if (context->InvokeService(context, _OrthancPluginService_GetOrthancDirectory, &params) != OrthancPluginErrorCode_Success)
3256 {
3257 /* Error */
3258 return NULL;
3259 }
3260 else
3261 {
3262 return result;
3263 }
3264 }
3265
3266
3267 /**
3268 * @brief Return the path to the configuration file(s).
3269 *
3270 * This function returns the path to the configuration file(s) that
3271 * was specified when starting Orthanc. Since version 0.9.1, this
3272 * path can refer to a folder that stores a set of configuration
3273 * files. This function is deprecated in favor of
3274 * OrthancPluginGetConfiguration().
3275 *
3276 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3277 * @return NULL in the case of an error, or a newly allocated string
3278 * containing the path. This string must be freed by
3279 * OrthancPluginFreeString().
3280 * @see OrthancPluginGetConfiguration()
3281 **/
3282 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfigurationPath(OrthancPluginContext* context)
3283 {
3284 char* result;
3285
3286 _OrthancPluginRetrieveDynamicString params;
3287 params.result = &result;
3288 params.argument = NULL;
3289
3290 if (context->InvokeService(context, _OrthancPluginService_GetConfigurationPath, &params) != OrthancPluginErrorCode_Success)
3291 {
3292 /* Error */
3293 return NULL;
3294 }
3295 else
3296 {
3297 return result;
3298 }
3299 }
3300
3301
3302
3303 typedef struct
3304 {
3305 OrthancPluginOnChangeCallback callback;
3306 } _OrthancPluginOnChangeCallback;
3307
3308 /**
3309 * @brief Register a callback to monitor changes.
3310 *
3311 * This function registers a callback function that is called
3312 * whenever a change happens to some DICOM resource.
3313 *
3314 * @warning Your callback function will be called synchronously with
3315 * the core of Orthanc. This implies that deadlocks might emerge if
3316 * you call other core primitives of Orthanc in your callback (such
3317 * deadlocks are particularly visible in the presence of other plugins
3318 * or Lua scripts). It is thus strongly advised to avoid any call to
3319 * the REST API of Orthanc in the callback. If you have to call
3320 * other primitives of Orthanc, you should make these calls in a
3321 * separate thread, passing the pending events to be processed
3322 * through a message queue.
3323 *
3324 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3325 * @param callback The callback function.
3326 * @ingroup Callbacks
3327 **/
3328 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterOnChangeCallback(
3329 OrthancPluginContext* context,
3330 OrthancPluginOnChangeCallback callback)
3331 {
3332 _OrthancPluginOnChangeCallback params;
3333 params.callback = callback;
3334
3335 context->InvokeService(context, _OrthancPluginService_RegisterOnChangeCallback, &params);
3336 }
3337
3338
3339
3340 typedef struct
3341 {
3342 const char* plugin;
3343 _OrthancPluginProperty property;
3344 const char* value;
3345 } _OrthancPluginSetPluginProperty;
3346
3347
3348 /**
3349 * @brief Set the URI where the plugin provides its Web interface.
3350 *
3351 * For plugins that come with a Web interface, this function
3352 * declares the entry path where to find this interface. This
3353 * information is notably used in the "Plugins" page of Orthanc
3354 * Explorer.
3355 *
3356 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3357 * @param uri The root URI for this plugin.
3358 **/
3359 ORTHANC_PLUGIN_INLINE void OrthancPluginSetRootUri(
3360 OrthancPluginContext* context,
3361 const char* uri)
3362 {
3363 _OrthancPluginSetPluginProperty params;
3364 params.plugin = OrthancPluginGetName();
3365 params.property = _OrthancPluginProperty_RootUri;
3366 params.value = uri;
3367
3368 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3369 }
3370
3371
3372 /**
3373 * @brief Set a description for this plugin.
3374 *
3375 * Set a description for this plugin. It is displayed in the
3376 * "Plugins" page of Orthanc Explorer.
3377 *
3378 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3379 * @param description The description.
3380 **/
3381 ORTHANC_PLUGIN_INLINE void OrthancPluginSetDescription(
3382 OrthancPluginContext* context,
3383 const char* description)
3384 {
3385 _OrthancPluginSetPluginProperty params;
3386 params.plugin = OrthancPluginGetName();
3387 params.property = _OrthancPluginProperty_Description;
3388 params.value = description;
3389
3390 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3391 }
3392
3393
3394 /**
3395 * @brief Extend the JavaScript code of Orthanc Explorer.
3396 *
3397 * Add JavaScript code to customize the default behavior of Orthanc
3398 * Explorer. This can for instance be used to add new buttons.
3399 *
3400 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3401 * @param javascript The custom JavaScript code.
3402 **/
3403 ORTHANC_PLUGIN_INLINE void OrthancPluginExtendOrthancExplorer(
3404 OrthancPluginContext* context,
3405 const char* javascript)
3406 {
3407 _OrthancPluginSetPluginProperty params;
3408 params.plugin = OrthancPluginGetName();
3409 params.property = _OrthancPluginProperty_OrthancExplorer;
3410 params.value = javascript;
3411
3412 context->InvokeService(context, _OrthancPluginService_SetPluginProperty, &params);
3413 }
3414
3415
3416 typedef struct
3417 {
3418 char** result;
3419 int32_t property;
3420 const char* value;
3421 } _OrthancPluginGlobalProperty;
3422
3423
3424 /**
3425 * @brief Get the value of a global property.
3426 *
3427 * Get the value of a global property that is stored in the Orthanc database. Global
3428 * properties whose index is below 1024 are reserved by Orthanc.
3429 *
3430 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3431 * @param property The global property of interest.
3432 * @param defaultValue The value to return, if the global property is unset.
3433 * @return The value of the global property, or NULL in the case of an error. This
3434 * string must be freed by OrthancPluginFreeString().
3435 * @ingroup Orthanc
3436 **/
3437 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetGlobalProperty(
3438 OrthancPluginContext* context,
3439 int32_t property,
3440 const char* defaultValue)
3441 {
3442 char* result;
3443
3444 _OrthancPluginGlobalProperty params;
3445 params.result = &result;
3446 params.property = property;
3447 params.value = defaultValue;
3448
3449 if (context->InvokeService(context, _OrthancPluginService_GetGlobalProperty, &params) != OrthancPluginErrorCode_Success)
3450 {
3451 /* Error */
3452 return NULL;
3453 }
3454 else
3455 {
3456 return result;
3457 }
3458 }
3459
3460
3461 /**
3462 * @brief Set the value of a global property.
3463 *
3464 * Set the value of a global property into the Orthanc
3465 * database. Setting a global property can be used by plugins to
3466 * save their internal parameters. Plugins are only allowed to set
3467 * properties whose index are above or equal to 1024 (properties
3468 * below 1024 are read-only and reserved by Orthanc).
3469 *
3470 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3471 * @param property The global property of interest.
3472 * @param value The value to be set in the global property.
3473 * @return 0 if success, or the error code if failure.
3474 * @ingroup Orthanc
3475 **/
3476 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSetGlobalProperty(
3477 OrthancPluginContext* context,
3478 int32_t property,
3479 const char* value)
3480 {
3481 _OrthancPluginGlobalProperty params;
3482 params.result = NULL;
3483 params.property = property;
3484 params.value = value;
3485
3486 return context->InvokeService(context, _OrthancPluginService_SetGlobalProperty, &params);
3487 }
3488
3489
3490
3491 typedef struct
3492 {
3493 int32_t *resultInt32;
3494 uint32_t *resultUint32;
3495 int64_t *resultInt64;
3496 uint64_t *resultUint64;
3497 } _OrthancPluginReturnSingleValue;
3498
3499 /**
3500 * @brief Get the number of command-line arguments.
3501 *
3502 * Retrieve the number of command-line arguments that were used to launch Orthanc.
3503 *
3504 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3505 * @return The number of arguments.
3506 **/
3507 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetCommandLineArgumentsCount(
3508 OrthancPluginContext* context)
3509 {
3510 uint32_t count = 0;
3511
3512 _OrthancPluginReturnSingleValue params;
3513 memset(&params, 0, sizeof(params));
3514 params.resultUint32 = &count;
3515
3516 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgumentsCount, &params) != OrthancPluginErrorCode_Success)
3517 {
3518 /* Error */
3519 return 0;
3520 }
3521 else
3522 {
3523 return count;
3524 }
3525 }
3526
3527
3528
3529 /**
3530 * @brief Get the value of a command-line argument.
3531 *
3532 * Get the value of one of the command-line arguments that were used
3533 * to launch Orthanc. The number of available arguments can be
3534 * retrieved by OrthancPluginGetCommandLineArgumentsCount().
3535 *
3536 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3537 * @param argument The index of the argument.
3538 * @return The value of the argument, or NULL in the case of an error. This
3539 * string must be freed by OrthancPluginFreeString().
3540 **/
3541 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetCommandLineArgument(
3542 OrthancPluginContext* context,
3543 uint32_t argument)
3544 {
3545 char* result;
3546
3547 _OrthancPluginGlobalProperty params;
3548 params.result = &result;
3549 params.property = (int32_t) argument;
3550 params.value = NULL;
3551
3552 if (context->InvokeService(context, _OrthancPluginService_GetCommandLineArgument, &params) != OrthancPluginErrorCode_Success)
3553 {
3554 /* Error */
3555 return NULL;
3556 }
3557 else
3558 {
3559 return result;
3560 }
3561 }
3562
3563
3564 /**
3565 * @brief Get the expected version of the database schema.
3566 *
3567 * Retrieve the expected version of the database schema.
3568 *
3569 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3570 * @return The version.
3571 * @ingroup Callbacks
3572 **/
3573 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetExpectedDatabaseVersion(
3574 OrthancPluginContext* context)
3575 {
3576 uint32_t count = 0;
3577
3578 _OrthancPluginReturnSingleValue params;
3579 memset(&params, 0, sizeof(params));
3580 params.resultUint32 = &count;
3581
3582 if (context->InvokeService(context, _OrthancPluginService_GetExpectedDatabaseVersion, &params) != OrthancPluginErrorCode_Success)
3583 {
3584 /* Error */
3585 return 0;
3586 }
3587 else
3588 {
3589 return count;
3590 }
3591 }
3592
3593
3594
3595 /**
3596 * @brief Return the content of the configuration file(s).
3597 *
3598 * This function returns the content of the configuration that is
3599 * used by Orthanc, formatted as a JSON string.
3600 *
3601 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3602 * @return NULL in the case of an error, or a newly allocated string
3603 * containing the configuration. This string must be freed by
3604 * OrthancPluginFreeString().
3605 **/
3606 ORTHANC_PLUGIN_INLINE char *OrthancPluginGetConfiguration(OrthancPluginContext* context)
3607 {
3608 char* result;
3609
3610 _OrthancPluginRetrieveDynamicString params;
3611 params.result = &result;
3612 params.argument = NULL;
3613
3614 if (context->InvokeService(context, _OrthancPluginService_GetConfiguration, &params) != OrthancPluginErrorCode_Success)
3615 {
3616 /* Error */
3617 return NULL;
3618 }
3619 else
3620 {
3621 return result;
3622 }
3623 }
3624
3625
3626
3627 typedef struct
3628 {
3629 OrthancPluginRestOutput* output;
3630 const char* subType;
3631 const char* contentType;
3632 } _OrthancPluginStartMultipartAnswer;
3633
3634 /**
3635 * @brief Start an HTTP multipart answer.
3636 *
3637 * Initiates a HTTP multipart answer, as the result of a REST request.
3638 *
3639 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3640 * @param output The HTTP connection to the client application.
3641 * @param subType The sub-type of the multipart answer ("mixed" or "related").
3642 * @param contentType The MIME type of the items in the multipart answer.
3643 * @return 0 if success, or the error code if failure.
3644 * @see OrthancPluginSendMultipartItem(), OrthancPluginSendMultipartItem2()
3645 * @ingroup REST
3646 **/
3647 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStartMultipartAnswer(
3648 OrthancPluginContext* context,
3649 OrthancPluginRestOutput* output,
3650 const char* subType,
3651 const char* contentType)
3652 {
3653 _OrthancPluginStartMultipartAnswer params;
3654 params.output = output;
3655 params.subType = subType;
3656 params.contentType = contentType;
3657 return context->InvokeService(context, _OrthancPluginService_StartMultipartAnswer, &params);
3658 }
3659
3660
3661 /**
3662 * @brief Send an item as a part of some HTTP multipart answer.
3663 *
3664 * This function sends an item as a part of some HTTP multipart
3665 * answer that was initiated by OrthancPluginStartMultipartAnswer().
3666 *
3667 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3668 * @param output The HTTP connection to the client application.
3669 * @param answer Pointer to the memory buffer containing the item.
3670 * @param answerSize Number of bytes of the item.
3671 * @return 0 if success, or the error code if failure (this notably happens
3672 * if the connection is closed by the client).
3673 * @see OrthancPluginSendMultipartItem2()
3674 * @ingroup REST
3675 **/
3676 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem(
3677 OrthancPluginContext* context,
3678 OrthancPluginRestOutput* output,
3679 const void* answer,
3680 uint32_t answerSize)
3681 {
3682 _OrthancPluginAnswerBuffer params;
3683 params.output = output;
3684 params.answer = answer;
3685 params.answerSize = answerSize;
3686 params.mimeType = NULL;
3687 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem, &params);
3688 }
3689
3690
3691
3692 typedef struct
3693 {
3694 OrthancPluginMemoryBuffer* target;
3695 const void* source;
3696 uint32_t size;
3697 OrthancPluginCompressionType compression;
3698 uint8_t uncompress;
3699 } _OrthancPluginBufferCompression;
3700
3701
3702 /**
3703 * @brief Compress or decompress a buffer.
3704 *
3705 * This function compresses or decompresses a buffer, using the
3706 * version of the zlib library that is used by the Orthanc core.
3707 *
3708 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3709 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3710 * @param source The source buffer.
3711 * @param size The size in bytes of the source buffer.
3712 * @param compression The compression algorithm.
3713 * @param uncompress If set to "0", the buffer must be compressed.
3714 * If set to "1", the buffer must be uncompressed.
3715 * @return 0 if success, or the error code if failure.
3716 * @ingroup Images
3717 **/
3718 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginBufferCompression(
3719 OrthancPluginContext* context,
3720 OrthancPluginMemoryBuffer* target,
3721 const void* source,
3722 uint32_t size,
3723 OrthancPluginCompressionType compression,
3724 uint8_t uncompress)
3725 {
3726 _OrthancPluginBufferCompression params;
3727 params.target = target;
3728 params.source = source;
3729 params.size = size;
3730 params.compression = compression;
3731 params.uncompress = uncompress;
3732
3733 return context->InvokeService(context, _OrthancPluginService_BufferCompression, &params);
3734 }
3735
3736
3737
3738 typedef struct
3739 {
3740 OrthancPluginMemoryBuffer* target;
3741 const char* path;
3742 } _OrthancPluginReadFile;
3743
3744 /**
3745 * @brief Read a file.
3746 *
3747 * Read the content of a file on the filesystem, and returns it into
3748 * a newly allocated memory buffer.
3749 *
3750 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3751 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
3752 * @param path The path of the file to be read.
3753 * @return 0 if success, or the error code if failure.
3754 **/
3755 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReadFile(
3756 OrthancPluginContext* context,
3757 OrthancPluginMemoryBuffer* target,
3758 const char* path)
3759 {
3760 _OrthancPluginReadFile params;
3761 params.target = target;
3762 params.path = path;
3763 return context->InvokeService(context, _OrthancPluginService_ReadFile, &params);
3764 }
3765
3766
3767
3768 typedef struct
3769 {
3770 const char* path;
3771 const void* data;
3772 uint32_t size;
3773 } _OrthancPluginWriteFile;
3774
3775 /**
3776 * @brief Write a file.
3777 *
3778 * Write the content of a memory buffer to the filesystem.
3779 *
3780 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3781 * @param path The path of the file to be written.
3782 * @param data The content of the memory buffer.
3783 * @param size The size of the memory buffer.
3784 * @return 0 if success, or the error code if failure.
3785 **/
3786 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWriteFile(
3787 OrthancPluginContext* context,
3788 const char* path,
3789 const void* data,
3790 uint32_t size)
3791 {
3792 _OrthancPluginWriteFile params;
3793 params.path = path;
3794 params.data = data;
3795 params.size = size;
3796 return context->InvokeService(context, _OrthancPluginService_WriteFile, &params);
3797 }
3798
3799
3800
3801 typedef struct
3802 {
3803 const char** target;
3804 OrthancPluginErrorCode error;
3805 } _OrthancPluginGetErrorDescription;
3806
3807 /**
3808 * @brief Get the description of a given error code.
3809 *
3810 * This function returns the description of a given error code.
3811 *
3812 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3813 * @param error The error code of interest.
3814 * @return The error description. This is a statically-allocated
3815 * string, do not free it.
3816 **/
3817 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetErrorDescription(
3818 OrthancPluginContext* context,
3819 OrthancPluginErrorCode error)
3820 {
3821 const char* result = NULL;
3822
3823 _OrthancPluginGetErrorDescription params;
3824 params.target = &result;
3825 params.error = error;
3826
3827 if (context->InvokeService(context, _OrthancPluginService_GetErrorDescription, &params) != OrthancPluginErrorCode_Success ||
3828 result == NULL)
3829 {
3830 return "Unknown error code";
3831 }
3832 else
3833 {
3834 return result;
3835 }
3836 }
3837
3838
3839
3840 typedef struct
3841 {
3842 OrthancPluginRestOutput* output;
3843 uint16_t status;
3844 const char* body;
3845 uint32_t bodySize;
3846 } _OrthancPluginSendHttpStatus;
3847
3848 /**
3849 * @brief Send a HTTP status, with a custom body.
3850 *
3851 * This function answers to a HTTP request by sending a HTTP status
3852 * code (such as "400 - Bad Request"), together with a body
3853 * describing the error. The body will only be returned if the
3854 * configuration option "HttpDescribeErrors" of Orthanc is set to "true".
3855 *
3856 * Note that:
3857 * - Successful requests (status 200) must use ::OrthancPluginAnswerBuffer().
3858 * - Redirections (status 301) must use ::OrthancPluginRedirect().
3859 * - Unauthorized access (status 401) must use ::OrthancPluginSendUnauthorized().
3860 * - Methods not allowed (status 405) must use ::OrthancPluginSendMethodNotAllowed().
3861 *
3862 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3863 * @param output The HTTP connection to the client application.
3864 * @param status The HTTP status code to be sent.
3865 * @param body The body of the answer.
3866 * @param bodySize The size of the body.
3867 * @see OrthancPluginSendHttpStatusCode()
3868 * @ingroup REST
3869 **/
3870 ORTHANC_PLUGIN_INLINE void OrthancPluginSendHttpStatus(
3871 OrthancPluginContext* context,
3872 OrthancPluginRestOutput* output,
3873 uint16_t status,
3874 const void* body,
3875 uint32_t bodySize)
3876 {
3877 _OrthancPluginSendHttpStatus params;
3878 params.output = output;
3879 params.status = status;
3880 params.body = reinterpret_cast<const char*>(body);
3881 params.bodySize = bodySize;
3882 context->InvokeService(context, _OrthancPluginService_SendHttpStatus, &params);
3883 }
3884
3885
3886
3887 typedef struct
3888 {
3889 const OrthancPluginImage* image;
3890 uint32_t* resultUint32;
3891 OrthancPluginPixelFormat* resultPixelFormat;
3892 void** resultBuffer;
3893 } _OrthancPluginGetImageInfo;
3894
3895
3896 /**
3897 * @brief Return the pixel format of an image.
3898 *
3899 * This function returns the type of memory layout for the pixels of the given image.
3900 *
3901 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3902 * @param image The image of interest.
3903 * @return The pixel format.
3904 * @ingroup Images
3905 **/
3906 ORTHANC_PLUGIN_INLINE OrthancPluginPixelFormat OrthancPluginGetImagePixelFormat(
3907 OrthancPluginContext* context,
3908 const OrthancPluginImage* image)
3909 {
3910 OrthancPluginPixelFormat target;
3911
3912 _OrthancPluginGetImageInfo params;
3913 memset(&params, 0, sizeof(params));
3914 params.image = image;
3915 params.resultPixelFormat = &target;
3916
3917 if (context->InvokeService(context, _OrthancPluginService_GetImagePixelFormat, &params) != OrthancPluginErrorCode_Success)
3918 {
3919 return OrthancPluginPixelFormat_Unknown;
3920 }
3921 else
3922 {
3923 return (OrthancPluginPixelFormat) target;
3924 }
3925 }
3926
3927
3928
3929 /**
3930 * @brief Return the width of an image.
3931 *
3932 * This function returns the width of the given image.
3933 *
3934 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3935 * @param image The image of interest.
3936 * @return The width.
3937 * @ingroup Images
3938 **/
3939 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageWidth(
3940 OrthancPluginContext* context,
3941 const OrthancPluginImage* image)
3942 {
3943 uint32_t width;
3944
3945 _OrthancPluginGetImageInfo params;
3946 memset(&params, 0, sizeof(params));
3947 params.image = image;
3948 params.resultUint32 = &width;
3949
3950 if (context->InvokeService(context, _OrthancPluginService_GetImageWidth, &params) != OrthancPluginErrorCode_Success)
3951 {
3952 return 0;
3953 }
3954 else
3955 {
3956 return width;
3957 }
3958 }
3959
3960
3961
3962 /**
3963 * @brief Return the height of an image.
3964 *
3965 * This function returns the height of the given image.
3966 *
3967 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
3968 * @param image The image of interest.
3969 * @return The height.
3970 * @ingroup Images
3971 **/
3972 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImageHeight(
3973 OrthancPluginContext* context,
3974 const OrthancPluginImage* image)
3975 {
3976 uint32_t height;
3977
3978 _OrthancPluginGetImageInfo params;
3979 memset(&params, 0, sizeof(params));
3980 params.image = image;
3981 params.resultUint32 = &height;
3982
3983 if (context->InvokeService(context, _OrthancPluginService_GetImageHeight, &params) != OrthancPluginErrorCode_Success)
3984 {
3985 return 0;
3986 }
3987 else
3988 {
3989 return height;
3990 }
3991 }
3992
3993
3994
3995 /**
3996 * @brief Return the pitch of an image.
3997 *
3998 * This function returns the pitch of the given image. The pitch is
3999 * defined as the number of bytes between 2 successive lines of the
4000 * image in the memory buffer.
4001 *
4002 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4003 * @param image The image of interest.
4004 * @return The pitch.
4005 * @ingroup Images
4006 **/
4007 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetImagePitch(
4008 OrthancPluginContext* context,
4009 const OrthancPluginImage* image)
4010 {
4011 uint32_t pitch;
4012
4013 _OrthancPluginGetImageInfo params;
4014 memset(&params, 0, sizeof(params));
4015 params.image = image;
4016 params.resultUint32 = &pitch;
4017
4018 if (context->InvokeService(context, _OrthancPluginService_GetImagePitch, &params) != OrthancPluginErrorCode_Success)
4019 {
4020 return 0;
4021 }
4022 else
4023 {
4024 return pitch;
4025 }
4026 }
4027
4028
4029
4030 /**
4031 * @brief Return a pointer to the content of an image.
4032 *
4033 * This function returns a pointer to the memory buffer that
4034 * contains the pixels of the image.
4035 *
4036 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4037 * @param image The image of interest.
4038 * @return The pointer.
4039 * @ingroup Images
4040 **/
4041 ORTHANC_PLUGIN_INLINE void* OrthancPluginGetImageBuffer(
4042 OrthancPluginContext* context,
4043 const OrthancPluginImage* image)
4044 {
4045 void* target = NULL;
4046
4047 _OrthancPluginGetImageInfo params;
4048 memset(&params, 0, sizeof(params));
4049 params.resultBuffer = &target;
4050 params.image = image;
4051
4052 if (context->InvokeService(context, _OrthancPluginService_GetImageBuffer, &params) != OrthancPluginErrorCode_Success)
4053 {
4054 return NULL;
4055 }
4056 else
4057 {
4058 return target;
4059 }
4060 }
4061
4062
4063 typedef struct
4064 {
4065 OrthancPluginImage** target;
4066 const void* data;
4067 uint32_t size;
4068 OrthancPluginImageFormat format;
4069 } _OrthancPluginUncompressImage;
4070
4071
4072 /**
4073 * @brief Decode a compressed image.
4074 *
4075 * This function decodes a compressed image from a memory buffer.
4076 *
4077 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4078 * @param data Pointer to a memory buffer containing the compressed image.
4079 * @param size Size of the memory buffer containing the compressed image.
4080 * @param format The file format of the compressed image.
4081 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
4082 * @ingroup Images
4083 **/
4084 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginUncompressImage(
4085 OrthancPluginContext* context,
4086 const void* data,
4087 uint32_t size,
4088 OrthancPluginImageFormat format)
4089 {
4090 OrthancPluginImage* target = NULL;
4091
4092 _OrthancPluginUncompressImage params;
4093 memset(&params, 0, sizeof(params));
4094 params.target = &target;
4095 params.data = data;
4096 params.size = size;
4097 params.format = format;
4098
4099 if (context->InvokeService(context, _OrthancPluginService_UncompressImage, &params) != OrthancPluginErrorCode_Success)
4100 {
4101 return NULL;
4102 }
4103 else
4104 {
4105 return target;
4106 }
4107 }
4108
4109
4110
4111
4112 typedef struct
4113 {
4114 OrthancPluginImage* image;
4115 } _OrthancPluginFreeImage;
4116
4117 /**
4118 * @brief Free an image.
4119 *
4120 * This function frees an image that was decoded with OrthancPluginUncompressImage().
4121 *
4122 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4123 * @param image The image.
4124 * @ingroup Images
4125 **/
4126 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeImage(
4127 OrthancPluginContext* context,
4128 OrthancPluginImage* image)
4129 {
4130 _OrthancPluginFreeImage params;
4131 params.image = image;
4132
4133 context->InvokeService(context, _OrthancPluginService_FreeImage, &params);
4134 }
4135
4136
4137
4138
4139 typedef struct
4140 {
4141 OrthancPluginMemoryBuffer* target;
4142 OrthancPluginImageFormat imageFormat;
4143 OrthancPluginPixelFormat pixelFormat;
4144 uint32_t width;
4145 uint32_t height;
4146 uint32_t pitch;
4147 const void* buffer;
4148 uint8_t quality;
4149 } _OrthancPluginCompressImage;
4150
4151
4152 /**
4153 * @brief Encode a PNG image.
4154 *
4155 * This function compresses the given memory buffer containing an
4156 * image using the PNG specification, and stores the result of the
4157 * compression into a newly allocated memory buffer.
4158 *
4159 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4160 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4161 * @param format The memory layout of the uncompressed image.
4162 * @param width The width of the image.
4163 * @param height The height of the image.
4164 * @param pitch The pitch of the image (i.e. the number of bytes
4165 * between 2 successive lines of the image in the memory buffer).
4166 * @param buffer The memory buffer containing the uncompressed image.
4167 * @return 0 if success, or the error code if failure.
4168 * @see OrthancPluginCompressAndAnswerPngImage()
4169 * @ingroup Images
4170 **/
4171 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressPngImage(
4172 OrthancPluginContext* context,
4173 OrthancPluginMemoryBuffer* target,
4174 OrthancPluginPixelFormat format,
4175 uint32_t width,
4176 uint32_t height,
4177 uint32_t pitch,
4178 const void* buffer)
4179 {
4180 _OrthancPluginCompressImage params;
4181 memset(&params, 0, sizeof(params));
4182 params.target = target;
4183 params.imageFormat = OrthancPluginImageFormat_Png;
4184 params.pixelFormat = format;
4185 params.width = width;
4186 params.height = height;
4187 params.pitch = pitch;
4188 params.buffer = buffer;
4189 params.quality = 0; /* Unused for PNG */
4190
4191 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
4192 }
4193
4194
4195 /**
4196 * @brief Encode a JPEG image.
4197 *
4198 * This function compresses the given memory buffer containing an
4199 * image using the JPEG specification, and stores the result of the
4200 * compression into a newly allocated memory buffer.
4201 *
4202 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4203 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4204 * @param format The memory layout of the uncompressed image.
4205 * @param width The width of the image.
4206 * @param height The height of the image.
4207 * @param pitch The pitch of the image (i.e. the number of bytes
4208 * between 2 successive lines of the image in the memory buffer).
4209 * @param buffer The memory buffer containing the uncompressed image.
4210 * @param quality The quality of the JPEG encoding, between 1 (worst
4211 * quality, best compression) and 100 (best quality, worst
4212 * compression).
4213 * @return 0 if success, or the error code if failure.
4214 * @ingroup Images
4215 **/
4216 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCompressJpegImage(
4217 OrthancPluginContext* context,
4218 OrthancPluginMemoryBuffer* target,
4219 OrthancPluginPixelFormat format,
4220 uint32_t width,
4221 uint32_t height,
4222 uint32_t pitch,
4223 const void* buffer,
4224 uint8_t quality)
4225 {
4226 _OrthancPluginCompressImage params;
4227 memset(&params, 0, sizeof(params));
4228 params.target = target;
4229 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4230 params.pixelFormat = format;
4231 params.width = width;
4232 params.height = height;
4233 params.pitch = pitch;
4234 params.buffer = buffer;
4235 params.quality = quality;
4236
4237 return context->InvokeService(context, _OrthancPluginService_CompressImage, &params);
4238 }
4239
4240
4241
4242 /**
4243 * @brief Answer to a REST request with a JPEG image.
4244 *
4245 * This function answers to a REST request with a JPEG image. The
4246 * parameters of this function describe a memory buffer that
4247 * contains an uncompressed image. The image will be automatically compressed
4248 * as a JPEG image by the core system of Orthanc.
4249 *
4250 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4251 * @param output The HTTP connection to the client application.
4252 * @param format The memory layout of the uncompressed image.
4253 * @param width The width of the image.
4254 * @param height The height of the image.
4255 * @param pitch The pitch of the image (i.e. the number of bytes
4256 * between 2 successive lines of the image in the memory buffer).
4257 * @param buffer The memory buffer containing the uncompressed image.
4258 * @param quality The quality of the JPEG encoding, between 1 (worst
4259 * quality, best compression) and 100 (best quality, worst
4260 * compression).
4261 * @ingroup REST
4262 **/
4263 ORTHANC_PLUGIN_INLINE void OrthancPluginCompressAndAnswerJpegImage(
4264 OrthancPluginContext* context,
4265 OrthancPluginRestOutput* output,
4266 OrthancPluginPixelFormat format,
4267 uint32_t width,
4268 uint32_t height,
4269 uint32_t pitch,
4270 const void* buffer,
4271 uint8_t quality)
4272 {
4273 _OrthancPluginCompressAndAnswerImage params;
4274 params.output = output;
4275 params.imageFormat = OrthancPluginImageFormat_Jpeg;
4276 params.pixelFormat = format;
4277 params.width = width;
4278 params.height = height;
4279 params.pitch = pitch;
4280 params.buffer = buffer;
4281 params.quality = quality;
4282 context->InvokeService(context, _OrthancPluginService_CompressAndAnswerImage, &params);
4283 }
4284
4285
4286
4287
4288 typedef struct
4289 {
4290 OrthancPluginMemoryBuffer* target;
4291 OrthancPluginHttpMethod method;
4292 const char* url;
4293 const char* username;
4294 const char* password;
4295 const void* body;
4296 uint32_t bodySize;
4297 } _OrthancPluginCallHttpClient;
4298
4299
4300 /**
4301 * @brief Issue a HTTP GET call.
4302 *
4303 * Make a HTTP GET call to the given URL. The result to the query is
4304 * stored into a newly allocated memory buffer. Favor
4305 * OrthancPluginRestApiGet() if calling the built-in REST API of the
4306 * Orthanc instance that hosts this plugin.
4307 *
4308 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4309 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4310 * @param url The URL of interest.
4311 * @param username The username (can be <tt>NULL</tt> if no password protection).
4312 * @param password The password (can be <tt>NULL</tt> if no password protection).
4313 * @return 0 if success, or the error code if failure.
4314 * @ingroup Toolbox
4315 **/
4316 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpGet(
4317 OrthancPluginContext* context,
4318 OrthancPluginMemoryBuffer* target,
4319 const char* url,
4320 const char* username,
4321 const char* password)
4322 {
4323 _OrthancPluginCallHttpClient params;
4324 memset(&params, 0, sizeof(params));
4325
4326 params.target = target;
4327 params.method = OrthancPluginHttpMethod_Get;
4328 params.url = url;
4329 params.username = username;
4330 params.password = password;
4331
4332 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4333 }
4334
4335
4336 /**
4337 * @brief Issue a HTTP POST call.
4338 *
4339 * Make a HTTP POST call to the given URL. The result to the query
4340 * is stored into a newly allocated memory buffer. Favor
4341 * OrthancPluginRestApiPost() if calling the built-in REST API of
4342 * the Orthanc instance that hosts this plugin.
4343 *
4344 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4345 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4346 * @param url The URL of interest.
4347 * @param body The content of the body of the request.
4348 * @param bodySize The size of the body of the request.
4349 * @param username The username (can be <tt>NULL</tt> if no password protection).
4350 * @param password The password (can be <tt>NULL</tt> if no password protection).
4351 * @return 0 if success, or the error code if failure.
4352 * @ingroup Toolbox
4353 **/
4354 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPost(
4355 OrthancPluginContext* context,
4356 OrthancPluginMemoryBuffer* target,
4357 const char* url,
4358 const void* body,
4359 uint32_t bodySize,
4360 const char* username,
4361 const char* password)
4362 {
4363 _OrthancPluginCallHttpClient params;
4364 memset(&params, 0, sizeof(params));
4365
4366 params.target = target;
4367 params.method = OrthancPluginHttpMethod_Post;
4368 params.url = url;
4369 params.body = body;
4370 params.bodySize = bodySize;
4371 params.username = username;
4372 params.password = password;
4373
4374 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4375 }
4376
4377
4378 /**
4379 * @brief Issue a HTTP PUT call.
4380 *
4381 * Make a HTTP PUT call to the given URL. The result to the query is
4382 * stored into a newly allocated memory buffer. Favor
4383 * OrthancPluginRestApiPut() if calling the built-in REST API of the
4384 * Orthanc instance that hosts this plugin.
4385 *
4386 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4387 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4388 * @param url The URL of interest.
4389 * @param body The content of the body of the request.
4390 * @param bodySize The size of the body of the request.
4391 * @param username The username (can be <tt>NULL</tt> if no password protection).
4392 * @param password The password (can be <tt>NULL</tt> if no password protection).
4393 * @return 0 if success, or the error code if failure.
4394 * @ingroup Toolbox
4395 **/
4396 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpPut(
4397 OrthancPluginContext* context,
4398 OrthancPluginMemoryBuffer* target,
4399 const char* url,
4400 const void* body,
4401 uint32_t bodySize,
4402 const char* username,
4403 const char* password)
4404 {
4405 _OrthancPluginCallHttpClient params;
4406 memset(&params, 0, sizeof(params));
4407
4408 params.target = target;
4409 params.method = OrthancPluginHttpMethod_Put;
4410 params.url = url;
4411 params.body = body;
4412 params.bodySize = bodySize;
4413 params.username = username;
4414 params.password = password;
4415
4416 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4417 }
4418
4419
4420 /**
4421 * @brief Issue a HTTP DELETE call.
4422 *
4423 * Make a HTTP DELETE call to the given URL. Favor
4424 * OrthancPluginRestApiDelete() if calling the built-in REST API of
4425 * the Orthanc instance that hosts this plugin.
4426 *
4427 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4428 * @param url The URL of interest.
4429 * @param username The username (can be <tt>NULL</tt> if no password protection).
4430 * @param password The password (can be <tt>NULL</tt> if no password protection).
4431 * @return 0 if success, or the error code if failure.
4432 * @ingroup Toolbox
4433 **/
4434 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpDelete(
4435 OrthancPluginContext* context,
4436 const char* url,
4437 const char* username,
4438 const char* password)
4439 {
4440 _OrthancPluginCallHttpClient params;
4441 memset(&params, 0, sizeof(params));
4442
4443 params.method = OrthancPluginHttpMethod_Delete;
4444 params.url = url;
4445 params.username = username;
4446 params.password = password;
4447
4448 return context->InvokeService(context, _OrthancPluginService_CallHttpClient, &params);
4449 }
4450
4451
4452
4453 typedef struct
4454 {
4455 OrthancPluginImage** target;
4456 const OrthancPluginImage* source;
4457 OrthancPluginPixelFormat targetFormat;
4458 } _OrthancPluginConvertPixelFormat;
4459
4460
4461 /**
4462 * @brief Change the pixel format of an image.
4463 *
4464 * This function creates a new image, changing the memory layout of the pixels.
4465 *
4466 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4467 * @param source The source image.
4468 * @param targetFormat The target pixel format.
4469 * @return The resulting image. It must be freed with OrthancPluginFreeImage().
4470 * @ingroup Images
4471 **/
4472 ORTHANC_PLUGIN_INLINE OrthancPluginImage *OrthancPluginConvertPixelFormat(
4473 OrthancPluginContext* context,
4474 const OrthancPluginImage* source,
4475 OrthancPluginPixelFormat targetFormat)
4476 {
4477 OrthancPluginImage* target = NULL;
4478
4479 _OrthancPluginConvertPixelFormat params;
4480 params.target = &target;
4481 params.source = source;
4482 params.targetFormat = targetFormat;
4483
4484 if (context->InvokeService(context, _OrthancPluginService_ConvertPixelFormat, &params) != OrthancPluginErrorCode_Success)
4485 {
4486 return NULL;
4487 }
4488 else
4489 {
4490 return target;
4491 }
4492 }
4493
4494
4495
4496 /**
4497 * @brief Return the number of available fonts.
4498 *
4499 * This function returns the number of fonts that are built in the
4500 * Orthanc core. These fonts can be used to draw texts on images
4501 * through OrthancPluginDrawText().
4502 *
4503 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4504 * @return The number of fonts.
4505 * @ingroup Images
4506 **/
4507 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontsCount(
4508 OrthancPluginContext* context)
4509 {
4510 uint32_t count = 0;
4511
4512 _OrthancPluginReturnSingleValue params;
4513 memset(&params, 0, sizeof(params));
4514 params.resultUint32 = &count;
4515
4516 if (context->InvokeService(context, _OrthancPluginService_GetFontsCount, &params) != OrthancPluginErrorCode_Success)
4517 {
4518 /* Error */
4519 return 0;
4520 }
4521 else
4522 {
4523 return count;
4524 }
4525 }
4526
4527
4528
4529
4530 typedef struct
4531 {
4532 uint32_t fontIndex; /* in */
4533 const char** name; /* out */
4534 uint32_t* size; /* out */
4535 } _OrthancPluginGetFontInfo;
4536
4537 /**
4538 * @brief Return the name of a font.
4539 *
4540 * This function returns the name of a font that is built in the Orthanc core.
4541 *
4542 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4543 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4544 * @return The font name. This is a statically-allocated string, do not free it.
4545 * @ingroup Images
4546 **/
4547 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetFontName(
4548 OrthancPluginContext* context,
4549 uint32_t fontIndex)
4550 {
4551 const char* result = NULL;
4552
4553 _OrthancPluginGetFontInfo params;
4554 memset(&params, 0, sizeof(params));
4555 params.name = &result;
4556 params.fontIndex = fontIndex;
4557
4558 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4559 {
4560 return NULL;
4561 }
4562 else
4563 {
4564 return result;
4565 }
4566 }
4567
4568
4569 /**
4570 * @brief Return the size of a font.
4571 *
4572 * This function returns the size of a font that is built in the Orthanc core.
4573 *
4574 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4575 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4576 * @return The font size.
4577 * @ingroup Images
4578 **/
4579 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFontSize(
4580 OrthancPluginContext* context,
4581 uint32_t fontIndex)
4582 {
4583 uint32_t result;
4584
4585 _OrthancPluginGetFontInfo params;
4586 memset(&params, 0, sizeof(params));
4587 params.size = &result;
4588 params.fontIndex = fontIndex;
4589
4590 if (context->InvokeService(context, _OrthancPluginService_GetFontInfo, &params) != OrthancPluginErrorCode_Success)
4591 {
4592 return 0;
4593 }
4594 else
4595 {
4596 return result;
4597 }
4598 }
4599
4600
4601
4602 typedef struct
4603 {
4604 OrthancPluginImage* image;
4605 uint32_t fontIndex;
4606 const char* utf8Text;
4607 int32_t x;
4608 int32_t y;
4609 uint8_t r;
4610 uint8_t g;
4611 uint8_t b;
4612 } _OrthancPluginDrawText;
4613
4614
4615 /**
4616 * @brief Draw text on an image.
4617 *
4618 * This function draws some text on some image.
4619 *
4620 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4621 * @param image The image upon which to draw the text.
4622 * @param fontIndex The index of the font. This value must be less than OrthancPluginGetFontsCount().
4623 * @param utf8Text The text to be drawn, encoded as an UTF-8 zero-terminated string.
4624 * @param x The X position of the text over the image.
4625 * @param y The Y position of the text over the image.
4626 * @param r The value of the red color channel of the text.
4627 * @param g The value of the green color channel of the text.
4628 * @param b The value of the blue color channel of the text.
4629 * @return 0 if success, other value if error.
4630 * @ingroup Images
4631 **/
4632 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginDrawText(
4633 OrthancPluginContext* context,
4634 OrthancPluginImage* image,
4635 uint32_t fontIndex,
4636 const char* utf8Text,
4637 int32_t x,
4638 int32_t y,
4639 uint8_t r,
4640 uint8_t g,
4641 uint8_t b)
4642 {
4643 _OrthancPluginDrawText params;
4644 memset(&params, 0, sizeof(params));
4645 params.image = image;
4646 params.fontIndex = fontIndex;
4647 params.utf8Text = utf8Text;
4648 params.x = x;
4649 params.y = y;
4650 params.r = r;
4651 params.g = g;
4652 params.b = b;
4653
4654 return context->InvokeService(context, _OrthancPluginService_DrawText, &params);
4655 }
4656
4657
4658
4659 typedef struct
4660 {
4661 OrthancPluginStorageArea* storageArea;
4662 const char* uuid;
4663 const void* content;
4664 uint64_t size;
4665 OrthancPluginContentType type;
4666 } _OrthancPluginStorageAreaCreate;
4667
4668
4669 /**
4670 * @brief Create a file inside the storage area.
4671 *
4672 * This function creates a new file inside the storage area that is
4673 * currently used by Orthanc.
4674 *
4675 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4676 * @param storageArea The storage area.
4677 * @param uuid The identifier of the file to be created.
4678 * @param content The content to store in the newly created file.
4679 * @param size The size of the content.
4680 * @param type The type of the file content.
4681 * @return 0 if success, other value if error.
4682 * @ingroup Callbacks
4683 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiPut()" on
4684 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead.
4685 **/
4686 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaCreate(
4687 OrthancPluginContext* context,
4688 OrthancPluginStorageArea* storageArea,
4689 const char* uuid,
4690 const void* content,
4691 uint64_t size,
4692 OrthancPluginContentType type)
4693 {
4694 _OrthancPluginStorageAreaCreate params;
4695 params.storageArea = storageArea;
4696 params.uuid = uuid;
4697 params.content = content;
4698 params.size = size;
4699 params.type = type;
4700
4701 return context->InvokeService(context, _OrthancPluginService_StorageAreaCreate, &params);
4702 }
4703
4704
4705 typedef struct
4706 {
4707 OrthancPluginMemoryBuffer* target;
4708 OrthancPluginStorageArea* storageArea;
4709 const char* uuid;
4710 OrthancPluginContentType type;
4711 } _OrthancPluginStorageAreaRead;
4712
4713
4714 /**
4715 * @brief Read a file from the storage area.
4716 *
4717 * This function reads the content of a given file from the storage
4718 * area that is currently used by Orthanc.
4719 *
4720 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4721 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
4722 * @param storageArea The storage area.
4723 * @param uuid The identifier of the file to be read.
4724 * @param type The type of the file content.
4725 * @return 0 if success, other value if error.
4726 * @ingroup Callbacks
4727 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiGet()" on
4728 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead.
4729 **/
4730 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRead(
4731 OrthancPluginContext* context,
4732 OrthancPluginMemoryBuffer* target,
4733 OrthancPluginStorageArea* storageArea,
4734 const char* uuid,
4735 OrthancPluginContentType type)
4736 {
4737 _OrthancPluginStorageAreaRead params;
4738 params.target = target;
4739 params.storageArea = storageArea;
4740 params.uuid = uuid;
4741 params.type = type;
4742
4743 return context->InvokeService(context, _OrthancPluginService_StorageAreaRead, &params);
4744 }
4745
4746
4747 typedef struct
4748 {
4749 OrthancPluginStorageArea* storageArea;
4750 const char* uuid;
4751 OrthancPluginContentType type;
4752 } _OrthancPluginStorageAreaRemove;
4753
4754 /**
4755 * @brief Remove a file from the storage area.
4756 *
4757 * This function removes a given file from the storage area that is
4758 * currently used by Orthanc.
4759 *
4760 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4761 * @param storageArea The storage area.
4762 * @param uuid The identifier of the file to be removed.
4763 * @param type The type of the file content.
4764 * @return 0 if success, other value if error.
4765 * @ingroup Callbacks
4766 * @deprecated This function should not be used anymore. Use "OrthancPluginRestApiDelete()" on
4767 * "/{patients|studies|series|instances}/{id}/attachments/{name}" instead.
4768 **/
4769 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginStorageAreaRemove(
4770 OrthancPluginContext* context,
4771 OrthancPluginStorageArea* storageArea,
4772 const char* uuid,
4773 OrthancPluginContentType type)
4774 {
4775 _OrthancPluginStorageAreaRemove params;
4776 params.storageArea = storageArea;
4777 params.uuid = uuid;
4778 params.type = type;
4779
4780 return context->InvokeService(context, _OrthancPluginService_StorageAreaRemove, &params);
4781 }
4782
4783
4784
4785 typedef struct
4786 {
4787 OrthancPluginErrorCode* target;
4788 int32_t code;
4789 uint16_t httpStatus;
4790 const char* message;
4791 } _OrthancPluginRegisterErrorCode;
4792
4793 /**
4794 * @brief Declare a custom error code for this plugin.
4795 *
4796 * This function declares a custom error code that can be generated
4797 * by this plugin. This declaration is used to enrich the body of
4798 * the HTTP answer in the case of an error, and to set the proper
4799 * HTTP status code.
4800 *
4801 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4802 * @param code The error code that is internal to this plugin.
4803 * @param httpStatus The HTTP status corresponding to this error.
4804 * @param message The description of the error.
4805 * @return The error code that has been assigned inside the Orthanc core.
4806 * @ingroup Toolbox
4807 **/
4808 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterErrorCode(
4809 OrthancPluginContext* context,
4810 int32_t code,
4811 uint16_t httpStatus,
4812 const char* message)
4813 {
4814 OrthancPluginErrorCode target;
4815
4816 _OrthancPluginRegisterErrorCode params;
4817 params.target = &target;
4818 params.code = code;
4819 params.httpStatus = httpStatus;
4820 params.message = message;
4821
4822 if (context->InvokeService(context, _OrthancPluginService_RegisterErrorCode, &params) == OrthancPluginErrorCode_Success)
4823 {
4824 return target;
4825 }
4826 else
4827 {
4828 /* There was an error while assigned the error. Use a generic code. */
4829 return OrthancPluginErrorCode_Plugin;
4830 }
4831 }
4832
4833
4834
4835 typedef struct
4836 {
4837 uint16_t group;
4838 uint16_t element;
4839 OrthancPluginValueRepresentation vr;
4840 const char* name;
4841 uint32_t minMultiplicity;
4842 uint32_t maxMultiplicity;
4843 } _OrthancPluginRegisterDictionaryTag;
4844
4845 /**
4846 * @brief Register a new tag into the DICOM dictionary.
4847 *
4848 * This function declares a new public tag in the dictionary of
4849 * DICOM tags that are known to Orthanc. This function should be
4850 * used in the OrthancPluginInitialize() callback.
4851 *
4852 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4853 * @param group The group of the tag.
4854 * @param element The element of the tag.
4855 * @param vr The value representation of the tag.
4856 * @param name The nickname of the tag.
4857 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4858 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4859 * an arbitrary multiplicity ("<tt>n</tt>").
4860 * @return 0 if success, other value if error.
4861 * @see OrthancPluginRegisterPrivateDictionaryTag()
4862 * @ingroup Toolbox
4863 **/
4864 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDictionaryTag(
4865 OrthancPluginContext* context,
4866 uint16_t group,
4867 uint16_t element,
4868 OrthancPluginValueRepresentation vr,
4869 const char* name,
4870 uint32_t minMultiplicity,
4871 uint32_t maxMultiplicity)
4872 {
4873 _OrthancPluginRegisterDictionaryTag params;
4874 params.group = group;
4875 params.element = element;
4876 params.vr = vr;
4877 params.name = name;
4878 params.minMultiplicity = minMultiplicity;
4879 params.maxMultiplicity = maxMultiplicity;
4880
4881 return context->InvokeService(context, _OrthancPluginService_RegisterDictionaryTag, &params);
4882 }
4883
4884
4885
4886 typedef struct
4887 {
4888 uint16_t group;
4889 uint16_t element;
4890 OrthancPluginValueRepresentation vr;
4891 const char* name;
4892 uint32_t minMultiplicity;
4893 uint32_t maxMultiplicity;
4894 const char* privateCreator;
4895 } _OrthancPluginRegisterPrivateDictionaryTag;
4896
4897 /**
4898 * @brief Register a new private tag into the DICOM dictionary.
4899 *
4900 * This function declares a new private tag in the dictionary of
4901 * DICOM tags that are known to Orthanc. This function should be
4902 * used in the OrthancPluginInitialize() callback.
4903 *
4904 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4905 * @param group The group of the tag.
4906 * @param element The element of the tag.
4907 * @param vr The value representation of the tag.
4908 * @param name The nickname of the tag.
4909 * @param minMultiplicity The minimum multiplicity of the tag (must be above 0).
4910 * @param maxMultiplicity The maximum multiplicity of the tag. A value of 0 means
4911 * an arbitrary multiplicity ("<tt>n</tt>").
4912 * @param privateCreator The private creator of this private tag.
4913 * @return 0 if success, other value if error.
4914 * @see OrthancPluginRegisterDictionaryTag()
4915 * @ingroup Toolbox
4916 **/
4917 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterPrivateDictionaryTag(
4918 OrthancPluginContext* context,
4919 uint16_t group,
4920 uint16_t element,
4921 OrthancPluginValueRepresentation vr,
4922 const char* name,
4923 uint32_t minMultiplicity,
4924 uint32_t maxMultiplicity,
4925 const char* privateCreator)
4926 {
4927 _OrthancPluginRegisterPrivateDictionaryTag params;
4928 params.group = group;
4929 params.element = element;
4930 params.vr = vr;
4931 params.name = name;
4932 params.minMultiplicity = minMultiplicity;
4933 params.maxMultiplicity = maxMultiplicity;
4934 params.privateCreator = privateCreator;
4935
4936 return context->InvokeService(context, _OrthancPluginService_RegisterPrivateDictionaryTag, &params);
4937 }
4938
4939
4940
4941 typedef struct
4942 {
4943 OrthancPluginStorageArea* storageArea;
4944 OrthancPluginResourceType level;
4945 } _OrthancPluginReconstructMainDicomTags;
4946
4947 /**
4948 * @brief Reconstruct the main DICOM tags.
4949 *
4950 * This function requests the Orthanc core to reconstruct the main
4951 * DICOM tags of all the resources of the given type. This function
4952 * can only be used as a part of the upgrade of a custom database
4953 * back-end. A database transaction will be automatically setup.
4954 *
4955 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4956 * @param storageArea The storage area.
4957 * @param level The type of the resources of interest.
4958 * @return 0 if success, other value if error.
4959 * @ingroup Callbacks
4960 **/
4961 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags(
4962 OrthancPluginContext* context,
4963 OrthancPluginStorageArea* storageArea,
4964 OrthancPluginResourceType level)
4965 {
4966 _OrthancPluginReconstructMainDicomTags params;
4967 params.level = level;
4968 params.storageArea = storageArea;
4969
4970 return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, &params);
4971 }
4972
4973
4974 typedef struct
4975 {
4976 char** result;
4977 const char* instanceId;
4978 const void* buffer;
4979 uint32_t size;
4980 OrthancPluginDicomToJsonFormat format;
4981 OrthancPluginDicomToJsonFlags flags;
4982 uint32_t maxStringLength;
4983 } _OrthancPluginDicomToJson;
4984
4985
4986 /**
4987 * @brief Format a DICOM memory buffer as a JSON string.
4988 *
4989 * This function takes as input a memory buffer containing a DICOM
4990 * file, and outputs a JSON string representing the tags of this
4991 * DICOM file.
4992 *
4993 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
4994 * @param buffer The memory buffer containing the DICOM file.
4995 * @param size The size of the memory buffer.
4996 * @param format The output format.
4997 * @param flags Flags governing the output.
4998 * @param maxStringLength The maximum length of a field. Too long fields will
4999 * be output as "null". The 0 value means no maximum length.
5000 * @return The NULL value if the case of an error, or the JSON
5001 * string. This string must be freed by OrthancPluginFreeString().
5002 * @ingroup Toolbox
5003 * @see OrthancPluginDicomInstanceToJson
5004 **/
5005 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomBufferToJson(
5006 OrthancPluginContext* context,
5007 const void* buffer,
5008 uint32_t size,
5009 OrthancPluginDicomToJsonFormat format,
5010 OrthancPluginDicomToJsonFlags flags,
5011 uint32_t maxStringLength)
5012 {
5013 char* result;
5014
5015 _OrthancPluginDicomToJson params;
5016 memset(&params, 0, sizeof(params));
5017 params.result = &result;
5018 params.buffer = buffer;
5019 params.size = size;
5020 params.format = format;
5021 params.flags = flags;
5022 params.maxStringLength = maxStringLength;
5023
5024 if (context->InvokeService(context, _OrthancPluginService_DicomBufferToJson, &params) != OrthancPluginErrorCode_Success)
5025 {
5026 /* Error */
5027 return NULL;
5028 }
5029 else
5030 {
5031 return result;
5032 }
5033 }
5034
5035
5036 /**
5037 * @brief Format a DICOM instance as a JSON string.
5038 *
5039 * This function formats a DICOM instance that is stored in Orthanc,
5040 * and outputs a JSON string representing the tags of this DICOM
5041 * instance.
5042 *
5043 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5044 * @param instanceId The Orthanc identifier of the instance.
5045 * @param format The output format.
5046 * @param flags Flags governing the output.
5047 * @param maxStringLength The maximum length of a field. Too long fields will
5048 * be output as "null". The 0 value means no maximum length.
5049 * @return The NULL value if the case of an error, or the JSON
5050 * string. This string must be freed by OrthancPluginFreeString().
5051 * @ingroup Toolbox
5052 * @see OrthancPluginDicomInstanceToJson
5053 **/
5054 ORTHANC_PLUGIN_INLINE char* OrthancPluginDicomInstanceToJson(
5055 OrthancPluginContext* context,
5056 const char* instanceId,
5057 OrthancPluginDicomToJsonFormat format,
5058 OrthancPluginDicomToJsonFlags flags,
5059 uint32_t maxStringLength)
5060 {
5061 char* result;
5062
5063 _OrthancPluginDicomToJson params;
5064 memset(&params, 0, sizeof(params));
5065 params.result = &result;
5066 params.instanceId = instanceId;
5067 params.format = format;
5068 params.flags = flags;
5069 params.maxStringLength = maxStringLength;
5070
5071 if (context->InvokeService(context, _OrthancPluginService_DicomInstanceToJson, &params) != OrthancPluginErrorCode_Success)
5072 {
5073 /* Error */
5074 return NULL;
5075 }
5076 else
5077 {
5078 return result;
5079 }
5080 }
5081
5082
5083 typedef struct
5084 {
5085 OrthancPluginMemoryBuffer* target;
5086 const char* uri;
5087 uint32_t headersCount;
5088 const char* const* headersKeys;
5089 const char* const* headersValues;
5090 int32_t afterPlugins;
5091 } _OrthancPluginRestApiGet2;
5092
5093 /**
5094 * @brief Make a GET call to the Orthanc REST API, with custom HTTP headers.
5095 *
5096 * Make a GET call to the Orthanc REST API with extended
5097 * parameters. The result to the query is stored into a newly
5098 * allocated memory buffer.
5099 *
5100 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5101 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
5102 * @param uri The URI in the built-in Orthanc API.
5103 * @param headersCount The number of HTTP headers.
5104 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
5105 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
5106 * @param afterPlugins If 0, the built-in API of Orthanc is used.
5107 * If 1, the API is tainted by the plugins.
5108 * @return 0 if success, or the error code if failure.
5109 * @see OrthancPluginRestApiGet, OrthancPluginRestApiGetAfterPlugins
5110 * @ingroup Orthanc
5111 **/
5112 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRestApiGet2(
5113 OrthancPluginContext* context,
5114 OrthancPluginMemoryBuffer* target,
5115 const char* uri,
5116 uint32_t headersCount,
5117 const char* const* headersKeys,
5118 const char* const* headersValues,
5119 int32_t afterPlugins)
5120 {
5121 _OrthancPluginRestApiGet2 params;
5122 params.target = target;
5123 params.uri = uri;
5124 params.headersCount = headersCount;
5125 params.headersKeys = headersKeys;
5126 params.headersValues = headersValues;
5127 params.afterPlugins = afterPlugins;
5128
5129 return context->InvokeService(context, _OrthancPluginService_RestApiGet2, &params);
5130 }
5131
5132
5133
5134 typedef struct
5135 {
5136 OrthancPluginWorklistCallback callback;
5137 } _OrthancPluginWorklistCallback;
5138
5139 /**
5140 * @brief Register a callback to handle modality worklists requests.
5141 *
5142 * This function registers a callback to handle C-Find SCP requests
5143 * on modality worklists.
5144 *
5145 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5146 * @param callback The callback.
5147 * @return 0 if success, other value if error.
5148 * @ingroup DicomCallbacks
5149 **/
5150 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterWorklistCallback(
5151 OrthancPluginContext* context,
5152 OrthancPluginWorklistCallback callback)
5153 {
5154 _OrthancPluginWorklistCallback params;
5155 params.callback = callback;
5156
5157 return context->InvokeService(context, _OrthancPluginService_RegisterWorklistCallback, &params);
5158 }
5159
5160
5161
5162 typedef struct
5163 {
5164 OrthancPluginWorklistAnswers* answers;
5165 const OrthancPluginWorklistQuery* query;
5166 const void* dicom;
5167 uint32_t size;
5168 } _OrthancPluginWorklistAnswersOperation;
5169
5170 /**
5171 * @brief Add one answer to some modality worklist request.
5172 *
5173 * This function adds one worklist (encoded as a DICOM file) to the
5174 * set of answers corresponding to some C-Find SCP request against
5175 * modality worklists.
5176 *
5177 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5178 * @param answers The set of answers.
5179 * @param query The worklist query, as received by the callback.
5180 * @param dicom The worklist to answer, encoded as a DICOM file.
5181 * @param size The size of the DICOM file.
5182 * @return 0 if success, other value if error.
5183 * @ingroup DicomCallbacks
5184 * @see OrthancPluginCreateDicom()
5185 **/
5186 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistAddAnswer(
5187 OrthancPluginContext* context,
5188 OrthancPluginWorklistAnswers* answers,
5189 const OrthancPluginWorklistQuery* query,
5190 const void* dicom,
5191 uint32_t size)
5192 {
5193 _OrthancPluginWorklistAnswersOperation params;
5194 params.answers = answers;
5195 params.query = query;
5196 params.dicom = dicom;
5197 params.size = size;
5198
5199 return context->InvokeService(context, _OrthancPluginService_WorklistAddAnswer, &params);
5200 }
5201
5202
5203 /**
5204 * @brief Mark the set of worklist answers as incomplete.
5205 *
5206 * This function marks as incomplete the set of answers
5207 * corresponding to some C-Find SCP request against modality
5208 * worklists. This must be used if canceling the handling of a
5209 * request when too many answers are to be returned.
5210 *
5211 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5212 * @param answers The set of answers.
5213 * @return 0 if success, other value if error.
5214 * @ingroup DicomCallbacks
5215 **/
5216 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistMarkIncomplete(
5217 OrthancPluginContext* context,
5218 OrthancPluginWorklistAnswers* answers)
5219 {
5220 _OrthancPluginWorklistAnswersOperation params;
5221 params.answers = answers;
5222 params.query = NULL;
5223 params.dicom = NULL;
5224 params.size = 0;
5225
5226 return context->InvokeService(context, _OrthancPluginService_WorklistMarkIncomplete, &params);
5227 }
5228
5229
5230 typedef struct
5231 {
5232 const OrthancPluginWorklistQuery* query;
5233 const void* dicom;
5234 uint32_t size;
5235 int32_t* isMatch;
5236 OrthancPluginMemoryBuffer* target;
5237 } _OrthancPluginWorklistQueryOperation;
5238
5239 /**
5240 * @brief Test whether a worklist matches the query.
5241 *
5242 * This function checks whether one worklist (encoded as a DICOM
5243 * file) matches the C-Find SCP query against modality
5244 * worklists. This function must be called before adding the
5245 * worklist as an answer through OrthancPluginWorklistAddAnswer().
5246 *
5247 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5248 * @param query The worklist query, as received by the callback.
5249 * @param dicom The worklist to answer, encoded as a DICOM file.
5250 * @param size The size of the DICOM file.
5251 * @return 1 if the worklist matches the query, 0 otherwise.
5252 * @ingroup DicomCallbacks
5253 **/
5254 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginWorklistIsMatch(
5255 OrthancPluginContext* context,
5256 const OrthancPluginWorklistQuery* query,
5257 const void* dicom,
5258 uint32_t size)
5259 {
5260 int32_t isMatch = 0;
5261
5262 _OrthancPluginWorklistQueryOperation params;
5263 params.query = query;
5264 params.dicom = dicom;
5265 params.size = size;
5266 params.isMatch = &isMatch;
5267 params.target = NULL;
5268
5269 if (context->InvokeService(context, _OrthancPluginService_WorklistIsMatch, &params) == OrthancPluginErrorCode_Success)
5270 {
5271 return isMatch;
5272 }
5273 else
5274 {
5275 /* Error: Assume non-match */
5276 return 0;
5277 }
5278 }
5279
5280
5281 /**
5282 * @brief Retrieve the worklist query as a DICOM file.
5283 *
5284 * This function retrieves the DICOM file that underlies a C-Find
5285 * SCP query against modality worklists.
5286 *
5287 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5288 * @param target Memory buffer where to store the DICOM file. It must be freed with OrthancPluginFreeMemoryBuffer().
5289 * @param query The worklist query, as received by the callback.
5290 * @return 0 if success, other value if error.
5291 * @ingroup DicomCallbacks
5292 **/
5293 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginWorklistGetDicomQuery(
5294 OrthancPluginContext* context,
5295 OrthancPluginMemoryBuffer* target,
5296 const OrthancPluginWorklistQuery* query)
5297 {
5298 _OrthancPluginWorklistQueryOperation params;
5299 params.query = query;
5300 params.dicom = NULL;
5301 params.size = 0;
5302 params.isMatch = NULL;
5303 params.target = target;
5304
5305 return context->InvokeService(context, _OrthancPluginService_WorklistGetDicomQuery, &params);
5306 }
5307
5308
5309 /**
5310 * @brief Get the origin of a DICOM file.
5311 *
5312 * This function returns the origin of a DICOM instance that has been received by Orthanc.
5313 *
5314 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5315 * @param instance The instance of interest.
5316 * @return The origin of the instance.
5317 * @ingroup DicomInstance
5318 **/
5319 ORTHANC_PLUGIN_INLINE OrthancPluginInstanceOrigin OrthancPluginGetInstanceOrigin(
5320 OrthancPluginContext* context,
5321 const OrthancPluginDicomInstance* instance)
5322 {
5323 OrthancPluginInstanceOrigin origin;
5324
5325 _OrthancPluginAccessDicomInstance params;
5326 memset(&params, 0, sizeof(params));
5327 params.resultOrigin = &origin;
5328 params.instance = instance;
5329
5330 if (context->InvokeService(context, _OrthancPluginService_GetInstanceOrigin, &params) != OrthancPluginErrorCode_Success)
5331 {
5332 /* Error */
5333 return OrthancPluginInstanceOrigin_Unknown;
5334 }
5335 else
5336 {
5337 return origin;
5338 }
5339 }
5340
5341
5342 typedef struct
5343 {
5344 OrthancPluginMemoryBuffer* target;
5345 const char* json;
5346 const OrthancPluginImage* pixelData;
5347 OrthancPluginCreateDicomFlags flags;
5348 } _OrthancPluginCreateDicom;
5349
5350 /**
5351 * @brief Create a DICOM instance from a JSON string and an image.
5352 *
5353 * This function takes as input a string containing a JSON file
5354 * describing the content of a DICOM instance. As an output, it
5355 * writes the corresponding DICOM instance to a newly allocated
5356 * memory buffer. Additionally, an image to be encoded within the
5357 * DICOM instance can also be provided.
5358 *
5359 * Private tags will be associated with the private creator whose
5360 * value is specified in the "DefaultPrivateCreator" configuration
5361 * option of Orthanc. The function OrthancPluginCreateDicom2() can
5362 * be used if another private creator must be used to create this
5363 * instance.
5364 *
5365 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5366 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
5367 * @param json The input JSON file.
5368 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
5369 * @param flags Flags governing the output.
5370 * @return 0 if success, other value if error.
5371 * @ingroup Toolbox
5372 * @see OrthancPluginCreateDicom2
5373 * @see OrthancPluginDicomBufferToJson
5374 **/
5375 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom(
5376 OrthancPluginContext* context,
5377 OrthancPluginMemoryBuffer* target,
5378 const char* json,
5379 const OrthancPluginImage* pixelData,
5380 OrthancPluginCreateDicomFlags flags)
5381 {
5382 _OrthancPluginCreateDicom params;
5383 params.target = target;
5384 params.json = json;
5385 params.pixelData = pixelData;
5386 params.flags = flags;
5387
5388 return context->InvokeService(context, _OrthancPluginService_CreateDicom, &params);
5389 }
5390
5391
5392 typedef struct
5393 {
5394 OrthancPluginDecodeImageCallback callback;
5395 } _OrthancPluginDecodeImageCallback;
5396
5397 /**
5398 * @brief Register a callback to handle the decoding of DICOM images.
5399 *
5400 * This function registers a custom callback to decode DICOM images,
5401 * extending the built-in decoder of Orthanc that uses
5402 * DCMTK. Starting with Orthanc 1.7.0, the exact behavior is
5403 * affected by the configuration option
5404 * "BuiltinDecoderTranscoderOrder" of Orthanc.
5405 *
5406 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5407 * @param callback The callback.
5408 * @return 0 if success, other value if error.
5409 * @ingroup Callbacks
5410 **/
5411 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterDecodeImageCallback(
5412 OrthancPluginContext* context,
5413 OrthancPluginDecodeImageCallback callback)
5414 {
5415 _OrthancPluginDecodeImageCallback params;
5416 params.callback = callback;
5417
5418 return context->InvokeService(context, _OrthancPluginService_RegisterDecodeImageCallback, &params);
5419 }
5420
5421
5422
5423 typedef struct
5424 {
5425 OrthancPluginImage** target;
5426 OrthancPluginPixelFormat format;
5427 uint32_t width;
5428 uint32_t height;
5429 uint32_t pitch;
5430 void* buffer;
5431 const void* constBuffer;
5432 uint32_t bufferSize;
5433 uint32_t frameIndex;
5434 } _OrthancPluginCreateImage;
5435
5436
5437 /**
5438 * @brief Create an image.
5439 *
5440 * This function creates an image of given size and format.
5441 *
5442 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5443 * @param format The format of the pixels.
5444 * @param width The width of the image.
5445 * @param height The height of the image.
5446 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5447 * @ingroup Images
5448 **/
5449 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImage(
5450 OrthancPluginContext* context,
5451 OrthancPluginPixelFormat format,
5452 uint32_t width,
5453 uint32_t height)
5454 {
5455 OrthancPluginImage* target = NULL;
5456
5457 _OrthancPluginCreateImage params;
5458 memset(&params, 0, sizeof(params));
5459 params.target = &target;
5460 params.format = format;
5461 params.width = width;
5462 params.height = height;
5463
5464 if (context->InvokeService(context, _OrthancPluginService_CreateImage, &params) != OrthancPluginErrorCode_Success)
5465 {
5466 return NULL;
5467 }
5468 else
5469 {
5470 return target;
5471 }
5472 }
5473
5474
5475 /**
5476 * @brief Create an image pointing to a memory buffer.
5477 *
5478 * This function creates an image whose content points to a memory
5479 * buffer managed by the plugin. Note that the buffer is directly
5480 * accessed, no memory is allocated and no data is copied.
5481 *
5482 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5483 * @param format The format of the pixels.
5484 * @param width The width of the image.
5485 * @param height The height of the image.
5486 * @param pitch The pitch of the image (i.e. the number of bytes
5487 * between 2 successive lines of the image in the memory buffer).
5488 * @param buffer The memory buffer.
5489 * @return The newly allocated image. It must be freed with OrthancPluginFreeImage().
5490 * @ingroup Images
5491 **/
5492 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginCreateImageAccessor(
5493 OrthancPluginContext* context,
5494 OrthancPluginPixelFormat format,
5495 uint32_t width,
5496 uint32_t height,
5497 uint32_t pitch,
5498 void* buffer)
5499 {
5500 OrthancPluginImage* target = NULL;
5501
5502 _OrthancPluginCreateImage params;
5503 memset(&params, 0, sizeof(params));
5504 params.target = &target;
5505 params.format = format;
5506 params.width = width;
5507 params.height = height;
5508 params.pitch = pitch;
5509 params.buffer = buffer;
5510
5511 if (context->InvokeService(context, _OrthancPluginService_CreateImageAccessor, &params) != OrthancPluginErrorCode_Success)
5512 {
5513 return NULL;
5514 }
5515 else
5516 {
5517 return target;
5518 }
5519 }
5520
5521
5522
5523 /**
5524 * @brief Decode one frame from a DICOM instance.
5525 *
5526 * This function decodes one frame of a DICOM image that is stored
5527 * in a memory buffer. This function will give the same result as
5528 * OrthancPluginUncompressImage() for single-frame DICOM images.
5529 *
5530 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5531 * @param buffer Pointer to a memory buffer containing the DICOM image.
5532 * @param bufferSize Size of the memory buffer containing the DICOM image.
5533 * @param frameIndex The index of the frame of interest in a multi-frame image.
5534 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
5535 * @ingroup Images
5536 * @see OrthancPluginGetInstanceDecodedFrame()
5537 **/
5538 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginDecodeDicomImage(
5539 OrthancPluginContext* context,
5540 const void* buffer,
5541 uint32_t bufferSize,
5542 uint32_t frameIndex)
5543 {
5544 OrthancPluginImage* target = NULL;
5545
5546 _OrthancPluginCreateImage params;
5547 memset(&params, 0, sizeof(params));
5548 params.target = &target;
5549 params.constBuffer = buffer;
5550 params.bufferSize = bufferSize;
5551 params.frameIndex = frameIndex;
5552
5553 if (context->InvokeService(context, _OrthancPluginService_DecodeDicomImage, &params) != OrthancPluginErrorCode_Success)
5554 {
5555 return NULL;
5556 }
5557 else
5558 {
5559 return target;
5560 }
5561 }
5562
5563
5564
5565 typedef struct
5566 {
5567 char** result;
5568 const void* buffer;
5569 uint32_t size;
5570 } _OrthancPluginComputeHash;
5571
5572 /**
5573 * @brief Compute an MD5 hash.
5574 *
5575 * This functions computes the MD5 cryptographic hash of the given memory buffer.
5576 *
5577 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5578 * @param buffer The source memory buffer.
5579 * @param size The size in bytes of the source buffer.
5580 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5581 * This string must be freed by OrthancPluginFreeString().
5582 * @ingroup Toolbox
5583 **/
5584 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeMd5(
5585 OrthancPluginContext* context,
5586 const void* buffer,
5587 uint32_t size)
5588 {
5589 char* result;
5590
5591 _OrthancPluginComputeHash params;
5592 params.result = &result;
5593 params.buffer = buffer;
5594 params.size = size;
5595
5596 if (context->InvokeService(context, _OrthancPluginService_ComputeMd5, &params) != OrthancPluginErrorCode_Success)
5597 {
5598 /* Error */
5599 return NULL;
5600 }
5601 else
5602 {
5603 return result;
5604 }
5605 }
5606
5607
5608 /**
5609 * @brief Compute a SHA-1 hash.
5610 *
5611 * This functions computes the SHA-1 cryptographic hash of the given memory buffer.
5612 *
5613 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5614 * @param buffer The source memory buffer.
5615 * @param size The size in bytes of the source buffer.
5616 * @return The NULL value in case of error, or a string containing the cryptographic hash.
5617 * This string must be freed by OrthancPluginFreeString().
5618 * @ingroup Toolbox
5619 **/
5620 ORTHANC_PLUGIN_INLINE char* OrthancPluginComputeSha1(
5621 OrthancPluginContext* context,
5622 const void* buffer,
5623 uint32_t size)
5624 {
5625 char* result;
5626
5627 _OrthancPluginComputeHash params;
5628 params.result = &result;
5629 params.buffer = buffer;
5630 params.size = size;
5631
5632 if (context->InvokeService(context, _OrthancPluginService_ComputeSha1, &params) != OrthancPluginErrorCode_Success)
5633 {
5634 /* Error */
5635 return NULL;
5636 }
5637 else
5638 {
5639 return result;
5640 }
5641 }
5642
5643
5644
5645 typedef struct
5646 {
5647 OrthancPluginDictionaryEntry* target;
5648 const char* name;
5649 } _OrthancPluginLookupDictionary;
5650
5651 /**
5652 * @brief Get information about the given DICOM tag.
5653 *
5654 * This functions makes a lookup in the dictionary of DICOM tags
5655 * that are known to Orthanc, and returns information about this
5656 * tag. The tag can be specified using its human-readable name
5657 * (e.g. "PatientName") or a set of two hexadecimal numbers
5658 * (e.g. "0010-0020").
5659 *
5660 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5661 * @param target Where to store the information about the tag.
5662 * @param name The name of the DICOM tag.
5663 * @return 0 if success, other value if error.
5664 * @ingroup Toolbox
5665 **/
5666 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginLookupDictionary(
5667 OrthancPluginContext* context,
5668 OrthancPluginDictionaryEntry* target,
5669 const char* name)
5670 {
5671 _OrthancPluginLookupDictionary params;
5672 params.target = target;
5673 params.name = name;
5674 return context->InvokeService(context, _OrthancPluginService_LookupDictionary, &params);
5675 }
5676
5677
5678
5679 typedef struct
5680 {
5681 OrthancPluginRestOutput* output;
5682 const void* answer;
5683 uint32_t answerSize;
5684 uint32_t headersCount;
5685 const char* const* headersKeys;
5686 const char* const* headersValues;
5687 } _OrthancPluginSendMultipartItem2;
5688
5689 /**
5690 * @brief Send an item as a part of some HTTP multipart answer, with custom headers.
5691 *
5692 * This function sends an item as a part of some HTTP multipart
5693 * answer that was initiated by OrthancPluginStartMultipartAnswer(). In addition to
5694 * OrthancPluginSendMultipartItem(), this function will set HTTP header associated
5695 * with the item.
5696 *
5697 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5698 * @param output The HTTP connection to the client application.
5699 * @param answer Pointer to the memory buffer containing the item.
5700 * @param answerSize Number of bytes of the item.
5701 * @param headersCount The number of HTTP headers.
5702 * @param headersKeys Array containing the keys of the HTTP headers.
5703 * @param headersValues Array containing the values of the HTTP headers.
5704 * @return 0 if success, or the error code if failure (this notably happens
5705 * if the connection is closed by the client).
5706 * @see OrthancPluginSendMultipartItem()
5707 * @ingroup REST
5708 **/
5709 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSendMultipartItem2(
5710 OrthancPluginContext* context,
5711 OrthancPluginRestOutput* output,
5712 const void* answer,
5713 uint32_t answerSize,
5714 uint32_t headersCount,
5715 const char* const* headersKeys,
5716 const char* const* headersValues)
5717 {
5718 _OrthancPluginSendMultipartItem2 params;
5719 params.output = output;
5720 params.answer = answer;
5721 params.answerSize = answerSize;
5722 params.headersCount = headersCount;
5723 params.headersKeys = headersKeys;
5724 params.headersValues = headersValues;
5725
5726 return context->InvokeService(context, _OrthancPluginService_SendMultipartItem2, &params);
5727 }
5728
5729
5730 typedef struct
5731 {
5732 OrthancPluginIncomingHttpRequestFilter callback;
5733 } _OrthancPluginIncomingHttpRequestFilter;
5734
5735 /**
5736 * @brief Register a callback to filter incoming HTTP requests.
5737 *
5738 * This function registers a custom callback to filter incoming HTTP/REST
5739 * requests received by the HTTP server of Orthanc.
5740 *
5741 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5742 * @param callback The callback.
5743 * @return 0 if success, other value if error.
5744 * @ingroup Callbacks
5745 * @deprecated Please instead use OrthancPluginRegisterIncomingHttpRequestFilter2()
5746 **/
5747 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter(
5748 OrthancPluginContext* context,
5749 OrthancPluginIncomingHttpRequestFilter callback)
5750 {
5751 _OrthancPluginIncomingHttpRequestFilter params;
5752 params.callback = callback;
5753
5754 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter, &params);
5755 }
5756
5757
5758
5759 typedef struct
5760 {
5761 OrthancPluginMemoryBuffer* answerBody;
5762 OrthancPluginMemoryBuffer* answerHeaders;
5763 uint16_t* httpStatus;
5764 OrthancPluginHttpMethod method;
5765 const char* url;
5766 uint32_t headersCount;
5767 const char* const* headersKeys;
5768 const char* const* headersValues;
5769 const void* body;
5770 uint32_t bodySize;
5771 const char* username;
5772 const char* password;
5773 uint32_t timeout;
5774 const char* certificateFile;
5775 const char* certificateKeyFile;
5776 const char* certificateKeyPassword;
5777 uint8_t pkcs11;
5778 } _OrthancPluginCallHttpClient2;
5779
5780
5781
5782 /**
5783 * @brief Issue a HTTP call with full flexibility.
5784 *
5785 * Make a HTTP call to the given URL. The result to the query is
5786 * stored into a newly allocated memory buffer. The HTTP request
5787 * will be done accordingly to the global configuration of Orthanc
5788 * (in particular, the options "HttpProxy", "HttpTimeout",
5789 * "HttpsVerifyPeers", "HttpsCACertificates", and "Pkcs11" will be
5790 * taken into account).
5791 *
5792 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5793 * @param answerBody The target memory buffer (out argument).
5794 * It must be freed with OrthancPluginFreeMemoryBuffer().
5795 * The value of this argument is ignored if the HTTP method is DELETE.
5796 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
5797 * The answer headers are formatted as a JSON object (associative array).
5798 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
5799 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
5800 * @param httpStatus The HTTP status after the execution of the request (out argument).
5801 * @param method HTTP method to be used.
5802 * @param url The URL of interest.
5803 * @param headersCount The number of HTTP headers.
5804 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
5805 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
5806 * @param username The username (can be <tt>NULL</tt> if no password protection).
5807 * @param password The password (can be <tt>NULL</tt> if no password protection).
5808 * @param body The HTTP body for a POST or PUT request.
5809 * @param bodySize The size of the body.
5810 * @param timeout Timeout in seconds (0 for default timeout).
5811 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
5812 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5813 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
5814 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5815 * @param certificateKeyPassword Password to unlock the key of the client certificate
5816 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
5817 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
5818 * @return 0 if success, or the error code if failure.
5819 * @see OrthancPluginCallPeerApi()
5820 * @ingroup Toolbox
5821 **/
5822 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginHttpClient(
5823 OrthancPluginContext* context,
5824 OrthancPluginMemoryBuffer* answerBody,
5825 OrthancPluginMemoryBuffer* answerHeaders,
5826 uint16_t* httpStatus,
5827 OrthancPluginHttpMethod method,
5828 const char* url,
5829 uint32_t headersCount,
5830 const char* const* headersKeys,
5831 const char* const* headersValues,
5832 const void* body,
5833 uint32_t bodySize,
5834 const char* username,
5835 const char* password,
5836 uint32_t timeout,
5837 const char* certificateFile,
5838 const char* certificateKeyFile,
5839 const char* certificateKeyPassword,
5840 uint8_t pkcs11)
5841 {
5842 _OrthancPluginCallHttpClient2 params;
5843 memset(&params, 0, sizeof(params));
5844
5845 params.answerBody = answerBody;
5846 params.answerHeaders = answerHeaders;
5847 params.httpStatus = httpStatus;
5848 params.method = method;
5849 params.url = url;
5850 params.headersCount = headersCount;
5851 params.headersKeys = headersKeys;
5852 params.headersValues = headersValues;
5853 params.body = body;
5854 params.bodySize = bodySize;
5855 params.username = username;
5856 params.password = password;
5857 params.timeout = timeout;
5858 params.certificateFile = certificateFile;
5859 params.certificateKeyFile = certificateKeyFile;
5860 params.certificateKeyPassword = certificateKeyPassword;
5861 params.pkcs11 = pkcs11;
5862
5863 return context->InvokeService(context, _OrthancPluginService_CallHttpClient2, &params);
5864 }
5865
5866
5867 /**
5868 * @brief Generate an UUID.
5869 *
5870 * Generate a random GUID/UUID (globally unique identifier).
5871 *
5872 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5873 * @return NULL in the case of an error, or a newly allocated string
5874 * containing the UUID. This string must be freed by OrthancPluginFreeString().
5875 * @ingroup Toolbox
5876 **/
5877 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateUuid(
5878 OrthancPluginContext* context)
5879 {
5880 char* result;
5881
5882 _OrthancPluginRetrieveDynamicString params;
5883 params.result = &result;
5884 params.argument = NULL;
5885
5886 if (context->InvokeService(context, _OrthancPluginService_GenerateUuid, &params) != OrthancPluginErrorCode_Success)
5887 {
5888 /* Error */
5889 return NULL;
5890 }
5891 else
5892 {
5893 return result;
5894 }
5895 }
5896
5897
5898
5899
5900 typedef struct
5901 {
5902 OrthancPluginFindCallback callback;
5903 } _OrthancPluginFindCallback;
5904
5905 /**
5906 * @brief Register a callback to handle C-Find requests.
5907 *
5908 * This function registers a callback to handle C-Find SCP requests
5909 * that are not related to modality worklists.
5910 *
5911 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5912 * @param callback The callback.
5913 * @return 0 if success, other value if error.
5914 * @ingroup DicomCallbacks
5915 **/
5916 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterFindCallback(
5917 OrthancPluginContext* context,
5918 OrthancPluginFindCallback callback)
5919 {
5920 _OrthancPluginFindCallback params;
5921 params.callback = callback;
5922
5923 return context->InvokeService(context, _OrthancPluginService_RegisterFindCallback, &params);
5924 }
5925
5926
5927 typedef struct
5928 {
5929 OrthancPluginFindAnswers *answers;
5930 const OrthancPluginFindQuery *query;
5931 const void *dicom;
5932 uint32_t size;
5933 uint32_t index;
5934 uint32_t *resultUint32;
5935 uint16_t *resultGroup;
5936 uint16_t *resultElement;
5937 char **resultString;
5938 } _OrthancPluginFindOperation;
5939
5940 /**
5941 * @brief Add one answer to some C-Find request.
5942 *
5943 * This function adds one answer (encoded as a DICOM file) to the
5944 * set of answers corresponding to some C-Find SCP request that is
5945 * not related to modality worklists.
5946 *
5947 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5948 * @param answers The set of answers.
5949 * @param dicom The answer to be added, encoded as a DICOM file.
5950 * @param size The size of the DICOM file.
5951 * @return 0 if success, other value if error.
5952 * @ingroup DicomCallbacks
5953 * @see OrthancPluginCreateDicom()
5954 **/
5955 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindAddAnswer(
5956 OrthancPluginContext* context,
5957 OrthancPluginFindAnswers* answers,
5958 const void* dicom,
5959 uint32_t size)
5960 {
5961 _OrthancPluginFindOperation params;
5962 memset(&params, 0, sizeof(params));
5963 params.answers = answers;
5964 params.dicom = dicom;
5965 params.size = size;
5966
5967 return context->InvokeService(context, _OrthancPluginService_FindAddAnswer, &params);
5968 }
5969
5970
5971 /**
5972 * @brief Mark the set of C-Find answers as incomplete.
5973 *
5974 * This function marks as incomplete the set of answers
5975 * corresponding to some C-Find SCP request that is not related to
5976 * modality worklists. This must be used if canceling the handling
5977 * of a request when too many answers are to be returned.
5978 *
5979 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
5980 * @param answers The set of answers.
5981 * @return 0 if success, other value if error.
5982 * @ingroup DicomCallbacks
5983 **/
5984 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginFindMarkIncomplete(
5985 OrthancPluginContext* context,
5986 OrthancPluginFindAnswers* answers)
5987 {
5988 _OrthancPluginFindOperation params;
5989 memset(&params, 0, sizeof(params));
5990 params.answers = answers;
5991
5992 return context->InvokeService(context, _OrthancPluginService_FindMarkIncomplete, &params);
5993 }
5994
5995
5996
5997 /**
5998 * @brief Get the number of tags in a C-Find query.
5999 *
6000 * This function returns the number of tags that are contained in
6001 * the given C-Find query.
6002 *
6003 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6004 * @param query The C-Find query.
6005 * @return The number of tags.
6006 * @ingroup DicomCallbacks
6007 **/
6008 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetFindQuerySize(
6009 OrthancPluginContext* context,
6010 const OrthancPluginFindQuery* query)
6011 {
6012 uint32_t count = 0;
6013
6014 _OrthancPluginFindOperation params;
6015 memset(&params, 0, sizeof(params));
6016 params.query = query;
6017 params.resultUint32 = &count;
6018
6019 if (context->InvokeService(context, _OrthancPluginService_GetFindQuerySize, &params) != OrthancPluginErrorCode_Success)
6020 {
6021 /* Error */
6022 return 0;
6023 }
6024 else
6025 {
6026 return count;
6027 }
6028 }
6029
6030
6031 /**
6032 * @brief Get one tag in a C-Find query.
6033 *
6034 * This function returns the group and the element of one DICOM tag
6035 * in the given C-Find query.
6036 *
6037 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6038 * @param group The group of the tag (output).
6039 * @param element The element of the tag (output).
6040 * @param query The C-Find query.
6041 * @param index The index of the tag of interest.
6042 * @return 0 if success, other value if error.
6043 * @ingroup DicomCallbacks
6044 **/
6045 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetFindQueryTag(
6046 OrthancPluginContext* context,
6047 uint16_t* group,
6048 uint16_t* element,
6049 const OrthancPluginFindQuery* query,
6050 uint32_t index)
6051 {
6052 _OrthancPluginFindOperation params;
6053 memset(&params, 0, sizeof(params));
6054 params.query = query;
6055 params.index = index;
6056 params.resultGroup = group;
6057 params.resultElement = element;
6058
6059 return context->InvokeService(context, _OrthancPluginService_GetFindQueryTag, &params);
6060 }
6061
6062
6063 /**
6064 * @brief Get the symbolic name of one tag in a C-Find query.
6065 *
6066 * This function returns the symbolic name of one DICOM tag in the
6067 * given C-Find query.
6068 *
6069 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6070 * @param query The C-Find query.
6071 * @param index The index of the tag of interest.
6072 * @return The NULL value in case of error, or a string containing the name of the tag.
6073 * @return 0 if success, other value if error.
6074 * @ingroup DicomCallbacks
6075 **/
6076 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryTagName(
6077 OrthancPluginContext* context,
6078 const OrthancPluginFindQuery* query,
6079 uint32_t index)
6080 {
6081 char* result;
6082
6083 _OrthancPluginFindOperation params;
6084 memset(&params, 0, sizeof(params));
6085 params.query = query;
6086 params.index = index;
6087 params.resultString = &result;
6088
6089 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryTagName, &params) != OrthancPluginErrorCode_Success)
6090 {
6091 /* Error */
6092 return NULL;
6093 }
6094 else
6095 {
6096 return result;
6097 }
6098 }
6099
6100
6101 /**
6102 * @brief Get the value associated with one tag in a C-Find query.
6103 *
6104 * This function returns the value associated with one tag in the
6105 * given C-Find query.
6106 *
6107 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6108 * @param query The C-Find query.
6109 * @param index The index of the tag of interest.
6110 * @return The NULL value in case of error, or a string containing the value of the tag.
6111 * @return 0 if success, other value if error.
6112 * @ingroup DicomCallbacks
6113 **/
6114 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetFindQueryValue(
6115 OrthancPluginContext* context,
6116 const OrthancPluginFindQuery* query,
6117 uint32_t index)
6118 {
6119 char* result;
6120
6121 _OrthancPluginFindOperation params;
6122 memset(&params, 0, sizeof(params));
6123 params.query = query;
6124 params.index = index;
6125 params.resultString = &result;
6126
6127 if (context->InvokeService(context, _OrthancPluginService_GetFindQueryValue, &params) != OrthancPluginErrorCode_Success)
6128 {
6129 /* Error */
6130 return NULL;
6131 }
6132 else
6133 {
6134 return result;
6135 }
6136 }
6137
6138
6139
6140
6141 typedef struct
6142 {
6143 OrthancPluginMoveCallback callback;
6144 OrthancPluginGetMoveSize getMoveSize;
6145 OrthancPluginApplyMove applyMove;
6146 OrthancPluginFreeMove freeMove;
6147 } _OrthancPluginMoveCallback;
6148
6149 /**
6150 * @brief Register a callback to handle C-Move requests.
6151 *
6152 * This function registers a callback to handle C-Move SCP requests.
6153 *
6154 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6155 * @param callback The main callback.
6156 * @param getMoveSize Callback to read the number of C-Move suboperations.
6157 * @param applyMove Callback to apply one C-Move suboperation.
6158 * @param freeMove Callback to free the C-Move driver.
6159 * @return 0 if success, other value if error.
6160 * @ingroup DicomCallbacks
6161 **/
6162 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterMoveCallback(
6163 OrthancPluginContext* context,
6164 OrthancPluginMoveCallback callback,
6165 OrthancPluginGetMoveSize getMoveSize,
6166 OrthancPluginApplyMove applyMove,
6167 OrthancPluginFreeMove freeMove)
6168 {
6169 _OrthancPluginMoveCallback params;
6170 params.callback = callback;
6171 params.getMoveSize = getMoveSize;
6172 params.applyMove = applyMove;
6173 params.freeMove = freeMove;
6174
6175 return context->InvokeService(context, _OrthancPluginService_RegisterMoveCallback, &params);
6176 }
6177
6178
6179
6180 typedef struct
6181 {
6182 OrthancPluginFindMatcher** target;
6183 const void* query;
6184 uint32_t size;
6185 } _OrthancPluginCreateFindMatcher;
6186
6187
6188 /**
6189 * @brief Create a C-Find matcher.
6190 *
6191 * This function creates a "matcher" object that can be used to
6192 * check whether a DICOM instance matches a C-Find query. The C-Find
6193 * query must be expressed as a DICOM buffer.
6194 *
6195 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6196 * @param query The C-Find DICOM query.
6197 * @param size The size of the DICOM query.
6198 * @return The newly allocated matcher. It must be freed with OrthancPluginFreeFindMatcher().
6199 * @ingroup Toolbox
6200 **/
6201 ORTHANC_PLUGIN_INLINE OrthancPluginFindMatcher* OrthancPluginCreateFindMatcher(
6202 OrthancPluginContext* context,
6203 const void* query,
6204 uint32_t size)
6205 {
6206 OrthancPluginFindMatcher* target = NULL;
6207
6208 _OrthancPluginCreateFindMatcher params;
6209 memset(&params, 0, sizeof(params));
6210 params.target = &target;
6211 params.query = query;
6212 params.size = size;
6213
6214 if (context->InvokeService(context, _OrthancPluginService_CreateFindMatcher, &params) != OrthancPluginErrorCode_Success)
6215 {
6216 return NULL;
6217 }
6218 else
6219 {
6220 return target;
6221 }
6222 }
6223
6224
6225 typedef struct
6226 {
6227 OrthancPluginFindMatcher* matcher;
6228 } _OrthancPluginFreeFindMatcher;
6229
6230 /**
6231 * @brief Free a C-Find matcher.
6232 *
6233 * This function frees a matcher that was created using OrthancPluginCreateFindMatcher().
6234 *
6235 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6236 * @param matcher The matcher of interest.
6237 * @ingroup Toolbox
6238 **/
6239 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeFindMatcher(
6240 OrthancPluginContext* context,
6241 OrthancPluginFindMatcher* matcher)
6242 {
6243 _OrthancPluginFreeFindMatcher params;
6244 params.matcher = matcher;
6245
6246 context->InvokeService(context, _OrthancPluginService_FreeFindMatcher, &params);
6247 }
6248
6249
6250 typedef struct
6251 {
6252 const OrthancPluginFindMatcher* matcher;
6253 const void* dicom;
6254 uint32_t size;
6255 int32_t* isMatch;
6256 } _OrthancPluginFindMatcherIsMatch;
6257
6258 /**
6259 * @brief Test whether a DICOM instance matches a C-Find query.
6260 *
6261 * This function checks whether one DICOM instance matches C-Find
6262 * matcher that was previously allocated using
6263 * OrthancPluginCreateFindMatcher().
6264 *
6265 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6266 * @param matcher The matcher of interest.
6267 * @param dicom The DICOM instance to be matched.
6268 * @param size The size of the DICOM instance.
6269 * @return 1 if the DICOM instance matches the query, 0 otherwise.
6270 * @ingroup Toolbox
6271 **/
6272 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginFindMatcherIsMatch(
6273 OrthancPluginContext* context,
6274 const OrthancPluginFindMatcher* matcher,
6275 const void* dicom,
6276 uint32_t size)
6277 {
6278 int32_t isMatch = 0;
6279
6280 _OrthancPluginFindMatcherIsMatch params;
6281 params.matcher = matcher;
6282 params.dicom = dicom;
6283 params.size = size;
6284 params.isMatch = &isMatch;
6285
6286 if (context->InvokeService(context, _OrthancPluginService_FindMatcherIsMatch, &params) == OrthancPluginErrorCode_Success)
6287 {
6288 return isMatch;
6289 }
6290 else
6291 {
6292 /* Error: Assume non-match */
6293 return 0;
6294 }
6295 }
6296
6297
6298 typedef struct
6299 {
6300 OrthancPluginIncomingHttpRequestFilter2 callback;
6301 } _OrthancPluginIncomingHttpRequestFilter2;
6302
6303 /**
6304 * @brief Register a callback to filter incoming HTTP requests.
6305 *
6306 * This function registers a custom callback to filter incoming HTTP/REST
6307 * requests received by the HTTP server of Orthanc.
6308 *
6309 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6310 * @param callback The callback.
6311 * @return 0 if success, other value if error.
6312 * @ingroup Callbacks
6313 **/
6314 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingHttpRequestFilter2(
6315 OrthancPluginContext* context,
6316 OrthancPluginIncomingHttpRequestFilter2 callback)
6317 {
6318 _OrthancPluginIncomingHttpRequestFilter2 params;
6319 params.callback = callback;
6320
6321 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingHttpRequestFilter2, &params);
6322 }
6323
6324
6325
6326 typedef struct
6327 {
6328 OrthancPluginPeers** peers;
6329 } _OrthancPluginGetPeers;
6330
6331 /**
6332 * @brief Return the list of available Orthanc peers.
6333 *
6334 * This function returns the parameters of the Orthanc peers that are known to
6335 * the Orthanc server hosting the plugin.
6336 *
6337 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6338 * @return NULL if error, or a newly allocated opaque data structure containing the peers.
6339 * This structure must be freed with OrthancPluginFreePeers().
6340 * @ingroup Toolbox
6341 **/
6342 ORTHANC_PLUGIN_INLINE OrthancPluginPeers* OrthancPluginGetPeers(
6343 OrthancPluginContext* context)
6344 {
6345 OrthancPluginPeers* peers = NULL;
6346
6347 _OrthancPluginGetPeers params;
6348 memset(&params, 0, sizeof(params));
6349 params.peers = &peers;
6350
6351 if (context->InvokeService(context, _OrthancPluginService_GetPeers, &params) != OrthancPluginErrorCode_Success)
6352 {
6353 return NULL;
6354 }
6355 else
6356 {
6357 return peers;
6358 }
6359 }
6360
6361
6362 typedef struct
6363 {
6364 OrthancPluginPeers* peers;
6365 } _OrthancPluginFreePeers;
6366
6367 /**
6368 * @brief Free the list of available Orthanc peers.
6369 *
6370 * This function frees the data structure returned by OrthancPluginGetPeers().
6371 *
6372 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6373 * @param peers The data structure describing the Orthanc peers.
6374 * @ingroup Toolbox
6375 **/
6376 ORTHANC_PLUGIN_INLINE void OrthancPluginFreePeers(
6377 OrthancPluginContext* context,
6378 OrthancPluginPeers* peers)
6379 {
6380 _OrthancPluginFreePeers params;
6381 params.peers = peers;
6382
6383 context->InvokeService(context, _OrthancPluginService_FreePeers, &params);
6384 }
6385
6386
6387 typedef struct
6388 {
6389 uint32_t* target;
6390 const OrthancPluginPeers* peers;
6391 } _OrthancPluginGetPeersCount;
6392
6393 /**
6394 * @brief Get the number of Orthanc peers.
6395 *
6396 * This function returns the number of Orthanc peers.
6397 *
6398 * This function is thread-safe: Several threads sharing the same
6399 * OrthancPluginPeers object can simultaneously call this function.
6400 *
6401 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6402 * @param peers The data structure describing the Orthanc peers.
6403 * @result The number of peers.
6404 * @ingroup Toolbox
6405 **/
6406 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetPeersCount(
6407 OrthancPluginContext* context,
6408 const OrthancPluginPeers* peers)
6409 {
6410 uint32_t target = 0;
6411
6412 _OrthancPluginGetPeersCount params;
6413 memset(&params, 0, sizeof(params));
6414 params.target = &target;
6415 params.peers = peers;
6416
6417 if (context->InvokeService(context, _OrthancPluginService_GetPeersCount, &params) != OrthancPluginErrorCode_Success)
6418 {
6419 /* Error */
6420 return 0;
6421 }
6422 else
6423 {
6424 return target;
6425 }
6426 }
6427
6428
6429 typedef struct
6430 {
6431 const char** target;
6432 const OrthancPluginPeers* peers;
6433 uint32_t peerIndex;
6434 const char* userProperty;
6435 } _OrthancPluginGetPeerProperty;
6436
6437 /**
6438 * @brief Get the symbolic name of an Orthanc peer.
6439 *
6440 * This function returns the symbolic name of the Orthanc peer,
6441 * which corresponds to the key of the "OrthancPeers" configuration
6442 * option of Orthanc.
6443 *
6444 * This function is thread-safe: Several threads sharing the same
6445 * OrthancPluginPeers object can simultaneously call this function.
6446 *
6447 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6448 * @param peers The data structure describing the Orthanc peers.
6449 * @param peerIndex The index of the peer of interest.
6450 * This value must be lower than OrthancPluginGetPeersCount().
6451 * @result The symbolic name, or NULL in the case of an error.
6452 * @ingroup Toolbox
6453 **/
6454 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerName(
6455 OrthancPluginContext* context,
6456 const OrthancPluginPeers* peers,
6457 uint32_t peerIndex)
6458 {
6459 const char* target = NULL;
6460
6461 _OrthancPluginGetPeerProperty params;
6462 memset(&params, 0, sizeof(params));
6463 params.target = &target;
6464 params.peers = peers;
6465 params.peerIndex = peerIndex;
6466 params.userProperty = NULL;
6467
6468 if (context->InvokeService(context, _OrthancPluginService_GetPeerName, &params) != OrthancPluginErrorCode_Success)
6469 {
6470 /* Error */
6471 return NULL;
6472 }
6473 else
6474 {
6475 return target;
6476 }
6477 }
6478
6479
6480 /**
6481 * @brief Get the base URL of an Orthanc peer.
6482 *
6483 * This function returns the base URL to the REST API of some Orthanc peer.
6484 *
6485 * This function is thread-safe: Several threads sharing the same
6486 * OrthancPluginPeers object can simultaneously call this function.
6487 *
6488 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6489 * @param peers The data structure describing the Orthanc peers.
6490 * @param peerIndex The index of the peer of interest.
6491 * This value must be lower than OrthancPluginGetPeersCount().
6492 * @result The URL, or NULL in the case of an error.
6493 * @ingroup Toolbox
6494 **/
6495 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUrl(
6496 OrthancPluginContext* context,
6497 const OrthancPluginPeers* peers,
6498 uint32_t peerIndex)
6499 {
6500 const char* target = NULL;
6501
6502 _OrthancPluginGetPeerProperty params;
6503 memset(&params, 0, sizeof(params));
6504 params.target = &target;
6505 params.peers = peers;
6506 params.peerIndex = peerIndex;
6507 params.userProperty = NULL;
6508
6509 if (context->InvokeService(context, _OrthancPluginService_GetPeerUrl, &params) != OrthancPluginErrorCode_Success)
6510 {
6511 /* Error */
6512 return NULL;
6513 }
6514 else
6515 {
6516 return target;
6517 }
6518 }
6519
6520
6521
6522 /**
6523 * @brief Get some user-defined property of an Orthanc peer.
6524 *
6525 * This function returns some user-defined property of some Orthanc
6526 * peer. An user-defined property is a property that is associated
6527 * with the peer in the Orthanc configuration file, but that is not
6528 * recognized by the Orthanc core.
6529 *
6530 * This function is thread-safe: Several threads sharing the same
6531 * OrthancPluginPeers object can simultaneously call this function.
6532 *
6533 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6534 * @param peers The data structure describing the Orthanc peers.
6535 * @param peerIndex The index of the peer of interest.
6536 * This value must be lower than OrthancPluginGetPeersCount().
6537 * @param userProperty The user property of interest.
6538 * @result The value of the user property, or NULL if it is not defined.
6539 * @ingroup Toolbox
6540 **/
6541 ORTHANC_PLUGIN_INLINE const char* OrthancPluginGetPeerUserProperty(
6542 OrthancPluginContext* context,
6543 const OrthancPluginPeers* peers,
6544 uint32_t peerIndex,
6545 const char* userProperty)
6546 {
6547 const char* target = NULL;
6548
6549 _OrthancPluginGetPeerProperty params;
6550 memset(&params, 0, sizeof(params));
6551 params.target = &target;
6552 params.peers = peers;
6553 params.peerIndex = peerIndex;
6554 params.userProperty = userProperty;
6555
6556 if (context->InvokeService(context, _OrthancPluginService_GetPeerUserProperty, &params) != OrthancPluginErrorCode_Success)
6557 {
6558 /* No such user property */
6559 return NULL;
6560 }
6561 else
6562 {
6563 return target;
6564 }
6565 }
6566
6567
6568
6569 typedef struct
6570 {
6571 OrthancPluginMemoryBuffer* answerBody;
6572 OrthancPluginMemoryBuffer* answerHeaders;
6573 uint16_t* httpStatus;
6574 const OrthancPluginPeers* peers;
6575 uint32_t peerIndex;
6576 OrthancPluginHttpMethod method;
6577 const char* uri;
6578 uint32_t additionalHeadersCount;
6579 const char* const* additionalHeadersKeys;
6580 const char* const* additionalHeadersValues;
6581 const void* body;
6582 uint32_t bodySize;
6583 uint32_t timeout;
6584 } _OrthancPluginCallPeerApi;
6585
6586 /**
6587 * @brief Call the REST API of an Orthanc peer.
6588 *
6589 * Make a REST call to the given URI in the REST API of a remote
6590 * Orthanc peer. The result to the query is stored into a newly
6591 * allocated memory buffer. The HTTP request will be done according
6592 * to the "OrthancPeers" configuration option of Orthanc.
6593 *
6594 * This function is thread-safe: Several threads sharing the same
6595 * OrthancPluginPeers object can simultaneously call this function.
6596 *
6597 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6598 * @param answerBody The target memory buffer (out argument).
6599 * It must be freed with OrthancPluginFreeMemoryBuffer().
6600 * The value of this argument is ignored if the HTTP method is DELETE.
6601 * @param answerHeaders The target memory buffer for the HTTP headers in the answers (out argument).
6602 * The answer headers are formatted as a JSON object (associative array).
6603 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
6604 * This argument can be set to NULL if the plugin has no interest in the HTTP headers.
6605 * @param httpStatus The HTTP status after the execution of the request (out argument).
6606 * @param peers The data structure describing the Orthanc peers.
6607 * @param peerIndex The index of the peer of interest.
6608 * This value must be lower than OrthancPluginGetPeersCount().
6609 * @param method HTTP method to be used.
6610 * @param uri The URI of interest in the REST API.
6611 * @param additionalHeadersCount The number of HTTP headers to be added to the
6612 * HTTP headers provided in the global configuration of Orthanc.
6613 * @param additionalHeadersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
6614 * @param additionalHeadersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
6615 * @param body The HTTP body for a POST or PUT request.
6616 * @param bodySize The size of the body.
6617 * @param timeout Timeout in seconds (0 for default timeout).
6618 * @return 0 if success, or the error code if failure.
6619 * @see OrthancPluginHttpClient()
6620 * @ingroup Toolbox
6621 **/
6622 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallPeerApi(
6623 OrthancPluginContext* context,
6624 OrthancPluginMemoryBuffer* answerBody,
6625 OrthancPluginMemoryBuffer* answerHeaders,
6626 uint16_t* httpStatus,
6627 const OrthancPluginPeers* peers,
6628 uint32_t peerIndex,
6629 OrthancPluginHttpMethod method,
6630 const char* uri,
6631 uint32_t additionalHeadersCount,
6632 const char* const* additionalHeadersKeys,
6633 const char* const* additionalHeadersValues,
6634 const void* body,
6635 uint32_t bodySize,
6636 uint32_t timeout)
6637 {
6638 _OrthancPluginCallPeerApi params;
6639 memset(&params, 0, sizeof(params));
6640
6641 params.answerBody = answerBody;
6642 params.answerHeaders = answerHeaders;
6643 params.httpStatus = httpStatus;
6644 params.peers = peers;
6645 params.peerIndex = peerIndex;
6646 params.method = method;
6647 params.uri = uri;
6648 params.additionalHeadersCount = additionalHeadersCount;
6649 params.additionalHeadersKeys = additionalHeadersKeys;
6650 params.additionalHeadersValues = additionalHeadersValues;
6651 params.body = body;
6652 params.bodySize = bodySize;
6653 params.timeout = timeout;
6654
6655 return context->InvokeService(context, _OrthancPluginService_CallPeerApi, &params);
6656 }
6657
6658
6659
6660
6661
6662 typedef struct
6663 {
6664 OrthancPluginJob** target;
6665 void *job;
6666 OrthancPluginJobFinalize finalize;
6667 const char *type;
6668 OrthancPluginJobGetProgress getProgress;
6669 OrthancPluginJobGetContent getContent;
6670 OrthancPluginJobGetSerialized getSerialized;
6671 OrthancPluginJobStep step;
6672 OrthancPluginJobStop stop;
6673 OrthancPluginJobReset reset;
6674 } _OrthancPluginCreateJob;
6675
6676 /**
6677 * @brief Create a custom job.
6678 *
6679 * This function creates a custom job to be run by the jobs engine
6680 * of Orthanc.
6681 *
6682 * Orthanc starts one dedicated thread per custom job that is
6683 * running. It is guaranteed that all the callbacks will only be
6684 * called from this single dedicated thread, in mutual exclusion: As
6685 * a consequence, it is *not* mandatory to protect the various
6686 * callbacks by mutexes.
6687 *
6688 * The custom job can nonetheless launch its own processing threads
6689 * on the first call to the "step()" callback, and stop them once
6690 * the "stop()" callback is called.
6691 *
6692 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6693 * @param job The job to be executed.
6694 * @param finalize The finalization callback.
6695 * @param type The type of the job, provided to the job unserializer.
6696 * See OrthancPluginRegisterJobsUnserializer().
6697 * @param getProgress The progress callback.
6698 * @param getContent The content callback.
6699 * @param getSerialized The serialization callback.
6700 * @param step The callback to execute the individual steps of the job.
6701 * @param stop The callback that is invoked once the job leaves the "running" state.
6702 * @param reset The callback that is invoked if a stopped job is started again.
6703 * @return The newly allocated job. It must be freed with OrthancPluginFreeJob(),
6704 * as long as it is not submitted with OrthancPluginSubmitJob().
6705 * @ingroup Toolbox
6706 **/
6707 ORTHANC_PLUGIN_INLINE OrthancPluginJob *OrthancPluginCreateJob(
6708 OrthancPluginContext *context,
6709 void *job,
6710 OrthancPluginJobFinalize finalize,
6711 const char *type,
6712 OrthancPluginJobGetProgress getProgress,
6713 OrthancPluginJobGetContent getContent,
6714 OrthancPluginJobGetSerialized getSerialized,
6715 OrthancPluginJobStep step,
6716 OrthancPluginJobStop stop,
6717 OrthancPluginJobReset reset)
6718 {
6719 OrthancPluginJob* target = NULL;
6720
6721 _OrthancPluginCreateJob params;
6722 memset(&params, 0, sizeof(params));
6723
6724 params.target = &target;
6725 params.job = job;
6726 params.finalize = finalize;
6727 params.type = type;
6728 params.getProgress = getProgress;
6729 params.getContent = getContent;
6730 params.getSerialized = getSerialized;
6731 params.step = step;
6732 params.stop = stop;
6733 params.reset = reset;
6734
6735 if (context->InvokeService(context, _OrthancPluginService_CreateJob, &params) != OrthancPluginErrorCode_Success ||
6736 target == NULL)
6737 {
6738 /* Error */
6739 return NULL;
6740 }
6741 else
6742 {
6743 return target;
6744 }
6745 }
6746
6747
6748 typedef struct
6749 {
6750 OrthancPluginJob* job;
6751 } _OrthancPluginFreeJob;
6752
6753 /**
6754 * @brief Free a custom job.
6755 *
6756 * This function frees an image that was created with OrthancPluginCreateJob().
6757 *
6758 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6759 * @param job The job.
6760 * @ingroup Toolbox
6761 **/
6762 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeJob(
6763 OrthancPluginContext* context,
6764 OrthancPluginJob* job)
6765 {
6766 _OrthancPluginFreeJob params;
6767 params.job = job;
6768
6769 context->InvokeService(context, _OrthancPluginService_FreeJob, &params);
6770 }
6771
6772
6773
6774 typedef struct
6775 {
6776 char** resultId;
6777 OrthancPluginJob *job;
6778 int32_t priority;
6779 } _OrthancPluginSubmitJob;
6780
6781 /**
6782 * @brief Submit a new job to the jobs engine of Orthanc.
6783 *
6784 * This function adds the given job to the pending jobs of
6785 * Orthanc. Orthanc will take take of freeing it by invoking the
6786 * finalization callback provided to OrthancPluginCreateJob().
6787 *
6788 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6789 * @param job The job, as received by OrthancPluginCreateJob().
6790 * @param priority The priority of the job.
6791 * @return ID of the newly-submitted job. This string must be freed by OrthancPluginFreeString().
6792 * @ingroup Toolbox
6793 **/
6794 ORTHANC_PLUGIN_INLINE char *OrthancPluginSubmitJob(
6795 OrthancPluginContext *context,
6796 OrthancPluginJob *job,
6797 int32_t priority)
6798 {
6799 char* resultId = NULL;
6800
6801 _OrthancPluginSubmitJob params;
6802 memset(&params, 0, sizeof(params));
6803
6804 params.resultId = &resultId;
6805 params.job = job;
6806 params.priority = priority;
6807
6808 if (context->InvokeService(context, _OrthancPluginService_SubmitJob, &params) != OrthancPluginErrorCode_Success ||
6809 resultId == NULL)
6810 {
6811 /* Error */
6812 return NULL;
6813 }
6814 else
6815 {
6816 return resultId;
6817 }
6818 }
6819
6820
6821
6822 typedef struct
6823 {
6824 OrthancPluginJobsUnserializer unserializer;
6825 } _OrthancPluginJobsUnserializer;
6826
6827 /**
6828 * @brief Register an unserializer for custom jobs.
6829 *
6830 * This function registers an unserializer that decodes custom jobs
6831 * from a JSON string. This callback is invoked when the jobs engine
6832 * of Orthanc is started (on Orthanc initialization), for each job
6833 * that is stored in the Orthanc database.
6834 *
6835 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6836 * @param unserializer The job unserializer.
6837 * @ingroup Callbacks
6838 **/
6839 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterJobsUnserializer(
6840 OrthancPluginContext* context,
6841 OrthancPluginJobsUnserializer unserializer)
6842 {
6843 _OrthancPluginJobsUnserializer params;
6844 params.unserializer = unserializer;
6845
6846 context->InvokeService(context, _OrthancPluginService_RegisterJobsUnserializer, &params);
6847 }
6848
6849
6850
6851 typedef struct
6852 {
6853 OrthancPluginRestOutput* output;
6854 const char* details;
6855 uint8_t log;
6856 } _OrthancPluginSetHttpErrorDetails;
6857
6858 /**
6859 * @brief Provide a detailed description for an HTTP error.
6860 *
6861 * This function sets the detailed description associated with an
6862 * HTTP error. This description will be displayed in the "Details"
6863 * field of the JSON body of the HTTP answer. It is only taken into
6864 * consideration if the REST callback returns an error code that is
6865 * different from "OrthancPluginErrorCode_Success", and if the
6866 * "HttpDescribeErrors" configuration option of Orthanc is set to
6867 * "true".
6868 *
6869 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6870 * @param output The HTTP connection to the client application.
6871 * @param details The details of the error message.
6872 * @param log Whether to also write the detailed error to the Orthanc logs.
6873 * @ingroup REST
6874 **/
6875 ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails(
6876 OrthancPluginContext* context,
6877 OrthancPluginRestOutput* output,
6878 const char* details,
6879 uint8_t log)
6880 {
6881 _OrthancPluginSetHttpErrorDetails params;
6882 params.output = output;
6883 params.details = details;
6884 params.log = log;
6885 context->InvokeService(context, _OrthancPluginService_SetHttpErrorDetails, &params);
6886 }
6887
6888
6889
6890 typedef struct
6891 {
6892 const char** result;
6893 const char* argument;
6894 } _OrthancPluginRetrieveStaticString;
6895
6896 /**
6897 * @brief Detect the MIME type of a file.
6898 *
6899 * This function returns the MIME type of a file by inspecting its extension.
6900 *
6901 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6902 * @param path Path to the file.
6903 * @return The MIME type. This is a statically-allocated
6904 * string, do not free it.
6905 * @ingroup Toolbox
6906 **/
6907 ORTHANC_PLUGIN_INLINE const char* OrthancPluginAutodetectMimeType(
6908 OrthancPluginContext* context,
6909 const char* path)
6910 {
6911 const char* result = NULL;
6912
6913 _OrthancPluginRetrieveStaticString params;
6914 params.result = &result;
6915 params.argument = path;
6916
6917 if (context->InvokeService(context, _OrthancPluginService_AutodetectMimeType, &params) != OrthancPluginErrorCode_Success)
6918 {
6919 /* Error */
6920 return NULL;
6921 }
6922 else
6923 {
6924 return result;
6925 }
6926 }
6927
6928
6929
6930 typedef struct
6931 {
6932 const char* name;
6933 float value;
6934 OrthancPluginMetricsType type;
6935 } _OrthancPluginSetMetricsValue;
6936
6937 /**
6938 * @brief Set the value of a metrics.
6939 *
6940 * This function sets the value of a metrics to monitor the behavior
6941 * of the plugin through tools such as Prometheus. The values of all
6942 * the metrics are stored within the Orthanc context.
6943 *
6944 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6945 * @param name The name of the metrics to be set.
6946 * @param value The value of the metrics.
6947 * @param type The type of the metrics. This parameter is only taken into consideration
6948 * the first time this metrics is set.
6949 * @ingroup Toolbox
6950 **/
6951 ORTHANC_PLUGIN_INLINE void OrthancPluginSetMetricsValue(
6952 OrthancPluginContext* context,
6953 const char* name,
6954 float value,
6955 OrthancPluginMetricsType type)
6956 {
6957 _OrthancPluginSetMetricsValue params;
6958 params.name = name;
6959 params.value = value;
6960 params.type = type;
6961 context->InvokeService(context, _OrthancPluginService_SetMetricsValue, &params);
6962 }
6963
6964
6965
6966 typedef struct
6967 {
6968 OrthancPluginRefreshMetricsCallback callback;
6969 } _OrthancPluginRegisterRefreshMetricsCallback;
6970
6971 /**
6972 * @brief Register a callback to refresh the metrics.
6973 *
6974 * This function registers a callback to refresh the metrics. The
6975 * callback must make calls to OrthancPluginSetMetricsValue().
6976 *
6977 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
6978 * @param callback The callback function to handle the refresh.
6979 * @ingroup Callbacks
6980 **/
6981 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterRefreshMetricsCallback(
6982 OrthancPluginContext* context,
6983 OrthancPluginRefreshMetricsCallback callback)
6984 {
6985 _OrthancPluginRegisterRefreshMetricsCallback params;
6986 params.callback = callback;
6987 context->InvokeService(context, _OrthancPluginService_RegisterRefreshMetricsCallback, &params);
6988 }
6989
6990
6991
6992
6993 typedef struct
6994 {
6995 char** target;
6996 const void* dicom;
6997 uint32_t dicomSize;
6998 OrthancPluginDicomWebBinaryCallback callback;
6999 } _OrthancPluginEncodeDicomWeb;
7000
7001 /**
7002 * @brief Convert a DICOM instance to DICOMweb JSON.
7003 *
7004 * This function converts a memory buffer containing a DICOM instance,
7005 * into its DICOMweb JSON representation.
7006 *
7007 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7008 * @param dicom Pointer to the DICOM instance.
7009 * @param dicomSize Size of the DICOM instance.
7010 * @param callback Callback to set the value of the binary tags.
7011 * @see OrthancPluginCreateDicom()
7012 * @return The NULL value in case of error, or the JSON document. This string must
7013 * be freed by OrthancPluginFreeString().
7014 * @deprecated OrthancPluginEncodeDicomWebJson2()
7015 * @ingroup Toolbox
7016 **/
7017 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson(
7018 OrthancPluginContext* context,
7019 const void* dicom,
7020 uint32_t dicomSize,
7021 OrthancPluginDicomWebBinaryCallback callback)
7022 {
7023 char* target = NULL;
7024
7025 _OrthancPluginEncodeDicomWeb params;
7026 params.target = &target;
7027 params.dicom = dicom;
7028 params.dicomSize = dicomSize;
7029 params.callback = callback;
7030
7031 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson, &params) != OrthancPluginErrorCode_Success)
7032 {
7033 /* Error */
7034 return NULL;
7035 }
7036 else
7037 {
7038 return target;
7039 }
7040 }
7041
7042
7043 /**
7044 * @brief Convert a DICOM instance to DICOMweb XML.
7045 *
7046 * This function converts a memory buffer containing a DICOM instance,
7047 * into its DICOMweb XML representation.
7048 *
7049 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7050 * @param dicom Pointer to the DICOM instance.
7051 * @param dicomSize Size of the DICOM instance.
7052 * @param callback Callback to set the value of the binary tags.
7053 * @return The NULL value in case of error, or the XML document. This string must
7054 * be freed by OrthancPluginFreeString().
7055 * @see OrthancPluginCreateDicom()
7056 * @deprecated OrthancPluginEncodeDicomWebXml2()
7057 * @ingroup Toolbox
7058 **/
7059 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml(
7060 OrthancPluginContext* context,
7061 const void* dicom,
7062 uint32_t dicomSize,
7063 OrthancPluginDicomWebBinaryCallback callback)
7064 {
7065 char* target = NULL;
7066
7067 _OrthancPluginEncodeDicomWeb params;
7068 params.target = &target;
7069 params.dicom = dicom;
7070 params.dicomSize = dicomSize;
7071 params.callback = callback;
7072
7073 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml, &params) != OrthancPluginErrorCode_Success)
7074 {
7075 /* Error */
7076 return NULL;
7077 }
7078 else
7079 {
7080 return target;
7081 }
7082 }
7083
7084
7085
7086 typedef struct
7087 {
7088 char** target;
7089 const void* dicom;
7090 uint32_t dicomSize;
7091 OrthancPluginDicomWebBinaryCallback2 callback;
7092 void* payload;
7093 } _OrthancPluginEncodeDicomWeb2;
7094
7095 /**
7096 * @brief Convert a DICOM instance to DICOMweb JSON.
7097 *
7098 * This function converts a memory buffer containing a DICOM instance,
7099 * into its DICOMweb JSON representation.
7100 *
7101 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7102 * @param dicom Pointer to the DICOM instance.
7103 * @param dicomSize Size of the DICOM instance.
7104 * @param callback Callback to set the value of the binary tags.
7105 * @param payload User payload.
7106 * @return The NULL value in case of error, or the JSON document. This string must
7107 * be freed by OrthancPluginFreeString().
7108 * @see OrthancPluginCreateDicom()
7109 * @ingroup Toolbox
7110 **/
7111 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebJson2(
7112 OrthancPluginContext* context,
7113 const void* dicom,
7114 uint32_t dicomSize,
7115 OrthancPluginDicomWebBinaryCallback2 callback,
7116 void* payload)
7117 {
7118 char* target = NULL;
7119
7120 _OrthancPluginEncodeDicomWeb2 params;
7121 params.target = &target;
7122 params.dicom = dicom;
7123 params.dicomSize = dicomSize;
7124 params.callback = callback;
7125 params.payload = payload;
7126
7127 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebJson2, &params) != OrthancPluginErrorCode_Success)
7128 {
7129 /* Error */
7130 return NULL;
7131 }
7132 else
7133 {
7134 return target;
7135 }
7136 }
7137
7138
7139 /**
7140 * @brief Convert a DICOM instance to DICOMweb XML.
7141 *
7142 * This function converts a memory buffer containing a DICOM instance,
7143 * into its DICOMweb XML representation.
7144 *
7145 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7146 * @param dicom Pointer to the DICOM instance.
7147 * @param dicomSize Size of the DICOM instance.
7148 * @param callback Callback to set the value of the binary tags.
7149 * @param payload User payload.
7150 * @return The NULL value in case of error, or the XML document. This string must
7151 * be freed by OrthancPluginFreeString().
7152 * @see OrthancPluginCreateDicom()
7153 * @ingroup Toolbox
7154 **/
7155 ORTHANC_PLUGIN_INLINE char* OrthancPluginEncodeDicomWebXml2(
7156 OrthancPluginContext* context,
7157 const void* dicom,
7158 uint32_t dicomSize,
7159 OrthancPluginDicomWebBinaryCallback2 callback,
7160 void* payload)
7161 {
7162 char* target = NULL;
7163
7164 _OrthancPluginEncodeDicomWeb2 params;
7165 params.target = &target;
7166 params.dicom = dicom;
7167 params.dicomSize = dicomSize;
7168 params.callback = callback;
7169 params.payload = payload;
7170
7171 if (context->InvokeService(context, _OrthancPluginService_EncodeDicomWebXml2, &params) != OrthancPluginErrorCode_Success)
7172 {
7173 /* Error */
7174 return NULL;
7175 }
7176 else
7177 {
7178 return target;
7179 }
7180 }
7181
7182
7183
7184 /**
7185 * @brief Callback executed when a HTTP header is received during a chunked transfer.
7186 *
7187 * Signature of a callback function that is called by Orthanc acting
7188 * as a HTTP client during a chunked HTTP transfer, as soon as it
7189 * receives one HTTP header from the answer of the remote HTTP
7190 * server.
7191 *
7192 * @see OrthancPluginChunkedHttpClient()
7193 * @param answer The user payload, as provided by the calling plugin.
7194 * @param key The key of the HTTP header.
7195 * @param value The value of the HTTP header.
7196 * @return 0 if success, or the error code if failure.
7197 * @ingroup Toolbox
7198 **/
7199 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddHeader) (
7200 void* answer,
7201 const char* key,
7202 const char* value);
7203
7204
7205 /**
7206 * @brief Callback executed when an answer chunk is received during a chunked transfer.
7207 *
7208 * Signature of a callback function that is called by Orthanc acting
7209 * as a HTTP client during a chunked HTTP transfer, as soon as it
7210 * receives one data chunk from the answer of the remote HTTP
7211 * server.
7212 *
7213 * @see OrthancPluginChunkedHttpClient()
7214 * @param answer The user payload, as provided by the calling plugin.
7215 * @param data The content of the data chunk.
7216 * @param size The size of the data chunk.
7217 * @return 0 if success, or the error code if failure.
7218 * @ingroup Toolbox
7219 **/
7220 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientAnswerAddChunk) (
7221 void* answer,
7222 const void* data,
7223 uint32_t size);
7224
7225
7226 /**
7227 * @brief Callback to know whether the request body is entirely read during a chunked transfer
7228 *
7229 * Signature of a callback function that is called by Orthanc acting
7230 * as a HTTP client during a chunked HTTP transfer, while reading
7231 * the body of a POST or PUT request. The plugin must answer "1" as
7232 * soon as the body is entirely read: The "request" data structure
7233 * must act as an iterator.
7234 *
7235 * @see OrthancPluginChunkedHttpClient()
7236 * @param request The user payload, as provided by the calling plugin.
7237 * @return "1" if the body is over, or "0" if there is still data to be read.
7238 * @ingroup Toolbox
7239 **/
7240 typedef uint8_t (*OrthancPluginChunkedClientRequestIsDone) (void* request);
7241
7242
7243 /**
7244 * @brief Callback to advance in the request body during a chunked transfer
7245 *
7246 * Signature of a callback function that is called by Orthanc acting
7247 * as a HTTP client during a chunked HTTP transfer, while reading
7248 * the body of a POST or PUT request. This function asks the plugin
7249 * to advance to the next chunk of data of the request body: The
7250 * "request" data structure must act as an iterator.
7251 *
7252 * @see OrthancPluginChunkedHttpClient()
7253 * @param request The user payload, as provided by the calling plugin.
7254 * @return 0 if success, or the error code if failure.
7255 * @ingroup Toolbox
7256 **/
7257 typedef OrthancPluginErrorCode (*OrthancPluginChunkedClientRequestNext) (void* request);
7258
7259
7260 /**
7261 * @brief Callback to read the current chunk of the request body during a chunked transfer
7262 *
7263 * Signature of a callback function that is called by Orthanc acting
7264 * as a HTTP client during a chunked HTTP transfer, while reading
7265 * the body of a POST or PUT request. The plugin must provide the
7266 * content of the current chunk of data of the request body.
7267 *
7268 * @see OrthancPluginChunkedHttpClient()
7269 * @param request The user payload, as provided by the calling plugin.
7270 * @return The content of the current request chunk.
7271 * @ingroup Toolbox
7272 **/
7273 typedef const void* (*OrthancPluginChunkedClientRequestGetChunkData) (void* request);
7274
7275
7276 /**
7277 * @brief Callback to read the size of the current request chunk during a chunked transfer
7278 *
7279 * Signature of a callback function that is called by Orthanc acting
7280 * as a HTTP client during a chunked HTTP transfer, while reading
7281 * the body of a POST or PUT request. The plugin must provide the
7282 * size of the current chunk of data of the request body.
7283 *
7284 * @see OrthancPluginChunkedHttpClient()
7285 * @param request The user payload, as provided by the calling plugin.
7286 * @return The size of the current request chunk.
7287 * @ingroup Toolbox
7288 **/
7289 typedef uint32_t (*OrthancPluginChunkedClientRequestGetChunkSize) (void* request);
7290
7291
7292 typedef struct
7293 {
7294 void* answer;
7295 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk;
7296 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader;
7297 uint16_t* httpStatus;
7298 OrthancPluginHttpMethod method;
7299 const char* url;
7300 uint32_t headersCount;
7301 const char* const* headersKeys;
7302 const char* const* headersValues;
7303 void* request;
7304 OrthancPluginChunkedClientRequestIsDone requestIsDone;
7305 OrthancPluginChunkedClientRequestGetChunkData requestChunkData;
7306 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize;
7307 OrthancPluginChunkedClientRequestNext requestNext;
7308 const char* username;
7309 const char* password;
7310 uint32_t timeout;
7311 const char* certificateFile;
7312 const char* certificateKeyFile;
7313 const char* certificateKeyPassword;
7314 uint8_t pkcs11;
7315 } _OrthancPluginChunkedHttpClient;
7316
7317
7318 /**
7319 * @brief Issue a HTTP call, using chunked HTTP transfers.
7320 *
7321 * Make a HTTP call to the given URL using chunked HTTP
7322 * transfers. The request body is provided as an iterator over data
7323 * chunks. The answer is provided as a sequence of function calls
7324 * with the individual HTTP headers and answer chunks.
7325 *
7326 * Contrarily to OrthancPluginHttpClient() that entirely stores the
7327 * request body and the answer body in memory buffers, this function
7328 * uses chunked HTTP transfers. This results in a lower memory
7329 * consumption. Pay attention to the fact that Orthanc servers with
7330 * version <= 1.5.6 do not support chunked transfers: You must use
7331 * OrthancPluginHttpClient() if contacting such older servers.
7332 *
7333 * The HTTP request will be done accordingly to the global
7334 * configuration of Orthanc (in particular, the options "HttpProxy",
7335 * "HttpTimeout", "HttpsVerifyPeers", "HttpsCACertificates", and
7336 * "Pkcs11" will be taken into account).
7337 *
7338 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7339 * @param answer The user payload for the answer body. It will be provided to the callbacks for the answer.
7340 * @param answerAddChunk Callback function to report a data chunk from the answer body.
7341 * @param answerAddHeader Callback function to report an HTTP header sent by the remote server.
7342 * @param httpStatus The HTTP status after the execution of the request (out argument).
7343 * @param method HTTP method to be used.
7344 * @param url The URL of interest.
7345 * @param headersCount The number of HTTP headers.
7346 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
7347 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
7348 * @param request The user payload containing the request body, and acting as an iterator.
7349 * It will be provided to the callbacks for the request.
7350 * @param requestIsDone Callback function to tell whether the request body is entirely read.
7351 * @param requestChunkData Callback function to get the content of the current data chunk of the request body.
7352 * @param requestChunkSize Callback function to get the size of the current data chunk of the request body.
7353 * @param requestNext Callback function to advance to the next data chunk of the request body.
7354 * @param username The username (can be <tt>NULL</tt> if no password protection).
7355 * @param password The password (can be <tt>NULL</tt> if no password protection).
7356 * @param timeout Timeout in seconds (0 for default timeout).
7357 * @param certificateFile Path to the client certificate for HTTPS, in PEM format
7358 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7359 * @param certificateKeyFile Path to the key of the client certificate for HTTPS, in PEM format
7360 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7361 * @param certificateKeyPassword Password to unlock the key of the client certificate
7362 * (can be <tt>NULL</tt> if no client certificate or if not using HTTPS).
7363 * @param pkcs11 Enable PKCS#11 client authentication for hardware security modules and smart cards.
7364 * @return 0 if success, or the error code if failure.
7365 * @see OrthancPluginHttpClient()
7366 * @ingroup Toolbox
7367 **/
7368 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginChunkedHttpClient(
7369 OrthancPluginContext* context,
7370 void* answer,
7371 OrthancPluginChunkedClientAnswerAddChunk answerAddChunk,
7372 OrthancPluginChunkedClientAnswerAddHeader answerAddHeader,
7373 uint16_t* httpStatus,
7374 OrthancPluginHttpMethod method,
7375 const char* url,
7376 uint32_t headersCount,
7377 const char* const* headersKeys,
7378 const char* const* headersValues,
7379 void* request,
7380 OrthancPluginChunkedClientRequestIsDone requestIsDone,
7381 OrthancPluginChunkedClientRequestGetChunkData requestChunkData,
7382 OrthancPluginChunkedClientRequestGetChunkSize requestChunkSize,
7383 OrthancPluginChunkedClientRequestNext requestNext,
7384 const char* username,
7385 const char* password,
7386 uint32_t timeout,
7387 const char* certificateFile,
7388 const char* certificateKeyFile,
7389 const char* certificateKeyPassword,
7390 uint8_t pkcs11)
7391 {
7392 _OrthancPluginChunkedHttpClient params;
7393 memset(&params, 0, sizeof(params));
7394
7395 /* In common with OrthancPluginHttpClient() */
7396 params.httpStatus = httpStatus;
7397 params.method = method;
7398 params.url = url;
7399 params.headersCount = headersCount;
7400 params.headersKeys = headersKeys;
7401 params.headersValues = headersValues;
7402 params.username = username;
7403 params.password = password;
7404 params.timeout = timeout;
7405 params.certificateFile = certificateFile;
7406 params.certificateKeyFile = certificateKeyFile;
7407 params.certificateKeyPassword = certificateKeyPassword;
7408 params.pkcs11 = pkcs11;
7409
7410 /* For chunked body/answer */
7411 params.answer = answer;
7412 params.answerAddChunk = answerAddChunk;
7413 params.answerAddHeader = answerAddHeader;
7414 params.request = request;
7415 params.requestIsDone = requestIsDone;
7416 params.requestChunkData = requestChunkData;
7417 params.requestChunkSize = requestChunkSize;
7418 params.requestNext = requestNext;
7419
7420 return context->InvokeService(context, _OrthancPluginService_ChunkedHttpClient, &params);
7421 }
7422
7423
7424
7425 /**
7426 * @brief Opaque structure that reads the content of a HTTP request body during a chunked HTTP transfer.
7427 * @ingroup Callback
7428 **/
7429 typedef struct _OrthancPluginServerChunkedRequestReader_t OrthancPluginServerChunkedRequestReader;
7430
7431
7432
7433 /**
7434 * @brief Callback to create a reader to handle incoming chunked HTTP transfers.
7435 *
7436 * Signature of a callback function that is called by Orthanc acting
7437 * as a HTTP server that supports chunked HTTP transfers. This
7438 * callback is only invoked if the HTTP method is POST or PUT. The
7439 * callback must create an user-specific "reader" object that will
7440 * be fed with the body of the incoming body.
7441 *
7442 * @see OrthancPluginRegisterChunkedRestCallback()
7443 * @param reader Memory location that must be filled with the newly-created reader.
7444 * @param url The URI that is accessed.
7445 * @param request The body of the HTTP request. Note that "body" and "bodySize" are not used.
7446 * @return 0 if success, or the error code if failure.
7447 **/
7448 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderFactory) (
7449 OrthancPluginServerChunkedRequestReader** reader,
7450 const char* url,
7451 const OrthancPluginHttpRequest* request);
7452
7453
7454 /**
7455 * @brief Callback invoked whenever a new data chunk is available during a chunked transfer.
7456 *
7457 * Signature of a callback function that is called by Orthanc acting
7458 * as a HTTP server that supports chunked HTTP transfers. This callback
7459 * is invoked as soon as a new data chunk is available for the request body.
7460 *
7461 * @see OrthancPluginRegisterChunkedRestCallback()
7462 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7463 * @param data The content of the data chunk.
7464 * @param size The size of the data chunk.
7465 * @return 0 if success, or the error code if failure.
7466 **/
7467 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderAddChunk) (
7468 OrthancPluginServerChunkedRequestReader* reader,
7469 const void* data,
7470 uint32_t size);
7471
7472
7473 /**
7474 * @brief Callback invoked whenever the request body is entirely received.
7475 *
7476 * Signature of a callback function that is called by Orthanc acting
7477 * as a HTTP server that supports chunked HTTP transfers. This
7478 * callback is invoked as soon as the full body of the HTTP request
7479 * is available. The plugin can then send its answer thanks to the
7480 * provided "output" object.
7481 *
7482 * @see OrthancPluginRegisterChunkedRestCallback()
7483 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7484 * @param output The HTTP connection to the client application.
7485 * @return 0 if success, or the error code if failure.
7486 **/
7487 typedef OrthancPluginErrorCode (*OrthancPluginServerChunkedRequestReaderExecute) (
7488 OrthancPluginServerChunkedRequestReader* reader,
7489 OrthancPluginRestOutput* output);
7490
7491
7492 /**
7493 * @brief Callback invoked to release the resources associated with an incoming HTTP chunked transfer.
7494 *
7495 * Signature of a callback function that is called by Orthanc acting
7496 * as a HTTP server that supports chunked HTTP transfers. This
7497 * callback is invoked to release all the resources allocated by the
7498 * given reader. Note that this function might be invoked even if
7499 * the entire body was not read, to deal with client error or
7500 * disconnection.
7501 *
7502 * @see OrthancPluginRegisterChunkedRestCallback()
7503 * @param reader The user payload, as created by the OrthancPluginServerChunkedRequestReaderFactory() callback.
7504 **/
7505 typedef void (*OrthancPluginServerChunkedRequestReaderFinalize) (
7506 OrthancPluginServerChunkedRequestReader* reader);
7507
7508 typedef struct
7509 {
7510 const char* pathRegularExpression;
7511 OrthancPluginRestCallback getHandler;
7512 OrthancPluginServerChunkedRequestReaderFactory postHandler;
7513 OrthancPluginRestCallback deleteHandler;
7514 OrthancPluginServerChunkedRequestReaderFactory putHandler;
7515 OrthancPluginServerChunkedRequestReaderAddChunk addChunk;
7516 OrthancPluginServerChunkedRequestReaderExecute execute;
7517 OrthancPluginServerChunkedRequestReaderFinalize finalize;
7518 } _OrthancPluginChunkedRestCallback;
7519
7520
7521 /**
7522 * @brief Register a REST callback to handle chunked HTTP transfers.
7523 *
7524 * This function registers a REST callback against a regular
7525 * expression for a URI. This function must be called during the
7526 * initialization of the plugin, i.e. inside the
7527 * OrthancPluginInitialize() public function.
7528 *
7529 * Contrarily to OrthancPluginRegisterRestCallback(), the callbacks
7530 * will NOT be invoked in mutual exclusion, so it is up to the
7531 * plugin to implement the required locking mechanisms.
7532 *
7533 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7534 * @param pathRegularExpression Regular expression for the URI. May contain groups.
7535 * @param getHandler The callback function to handle REST calls using the GET HTTP method.
7536 * @param postHandler The callback function to handle REST calls using the POST HTTP method.
7537 * @param deleteHandler The callback function to handle REST calls using the DELETE HTTP method.
7538 * @param putHandler The callback function to handle REST calls using the PUT HTTP method.
7539 * @param addChunk The callback invoked when a new chunk is available for the request body of a POST or PUT call.
7540 * @param execute The callback invoked once the entire body of a POST or PUT call is read.
7541 * @param finalize The callback invoked to release the resources associated with a POST or PUT call.
7542 * @see OrthancPluginRegisterRestCallbackNoLock()
7543 *
7544 * @note
7545 * The regular expression is case sensitive and must follow the
7546 * [Perl syntax](https://www.boost.org/doc/libs/1_67_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html).
7547 *
7548 * @ingroup Callbacks
7549 **/
7550 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterChunkedRestCallback(
7551 OrthancPluginContext* context,
7552 const char* pathRegularExpression,
7553 OrthancPluginRestCallback getHandler,
7554 OrthancPluginServerChunkedRequestReaderFactory postHandler,
7555 OrthancPluginRestCallback deleteHandler,
7556 OrthancPluginServerChunkedRequestReaderFactory putHandler,
7557 OrthancPluginServerChunkedRequestReaderAddChunk addChunk,
7558 OrthancPluginServerChunkedRequestReaderExecute execute,
7559 OrthancPluginServerChunkedRequestReaderFinalize finalize)
7560 {
7561 _OrthancPluginChunkedRestCallback params;
7562 params.pathRegularExpression = pathRegularExpression;
7563 params.getHandler = getHandler;
7564 params.postHandler = postHandler;
7565 params.deleteHandler = deleteHandler;
7566 params.putHandler = putHandler;
7567 params.addChunk = addChunk;
7568 params.execute = execute;
7569 params.finalize = finalize;
7570
7571 context->InvokeService(context, _OrthancPluginService_RegisterChunkedRestCallback, &params);
7572 }
7573
7574
7575
7576
7577
7578 typedef struct
7579 {
7580 char** result;
7581 uint16_t group;
7582 uint16_t element;
7583 const char* privateCreator;
7584 } _OrthancPluginGetTagName;
7585
7586 /**
7587 * @brief Returns the symbolic name of a DICOM tag.
7588 *
7589 * This function makes a lookup to the dictionary of DICOM tags that
7590 * are known to Orthanc, and returns the symbolic name of a DICOM tag.
7591 *
7592 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7593 * @param group The group of the tag.
7594 * @param element The element of the tag.
7595 * @param privateCreator For private tags, the name of the private creator (can be NULL).
7596 * @return NULL in the case of an error, or a newly allocated string
7597 * containing the path. This string must be freed by
7598 * OrthancPluginFreeString().
7599 * @ingroup Toolbox
7600 **/
7601 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetTagName(
7602 OrthancPluginContext* context,
7603 uint16_t group,
7604 uint16_t element,
7605 const char* privateCreator)
7606 {
7607 char* result;
7608
7609 _OrthancPluginGetTagName params;
7610 params.result = &result;
7611 params.group = group;
7612 params.element = element;
7613 params.privateCreator = privateCreator;
7614
7615 if (context->InvokeService(context, _OrthancPluginService_GetTagName, &params) != OrthancPluginErrorCode_Success)
7616 {
7617 /* Error */
7618 return NULL;
7619 }
7620 else
7621 {
7622 return result;
7623 }
7624 }
7625
7626
7627
7628 /**
7629 * @brief Callback executed by the storage commitment SCP.
7630 *
7631 * Signature of a factory function that creates an object to handle
7632 * one incoming storage commitment request.
7633 *
7634 * @remark The factory receives the list of the SOP class/instance
7635 * UIDs of interest to the remote storage commitment SCU. This gives
7636 * the factory the possibility to start some prefetch process
7637 * upfront in the background, before the handler object is actually
7638 * queried about the status of these DICOM instances.
7639 *
7640 * @param handler Output variable where the factory puts the handler object it created.
7641 * @param jobId ID of the Orthanc job that is responsible for handling
7642 * the storage commitment request. This job will successively look for the
7643 * status of all the individual queried DICOM instances.
7644 * @param transactionUid UID of the storage commitment transaction
7645 * provided by the storage commitment SCU. It contains the value of the
7646 * (0008,1195) DICOM tag.
7647 * @param sopClassUids Array of the SOP class UIDs (0008,0016) that are queried by the SCU.
7648 * @param sopInstanceUids Array of the SOP instance UIDs (0008,0018) that are queried by the SCU.
7649 * @param countInstances Number of DICOM instances that are queried. This is the size
7650 * of the `sopClassUids` and `sopInstanceUids` arrays.
7651 * @param remoteAet The AET of the storage commitment SCU.
7652 * @param calledAet The AET used by the SCU to contact the storage commitment SCP (i.e. Orthanc).
7653 * @return 0 if success, other value if error.
7654 * @ingroup DicomCallbacks
7655 **/
7656 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentFactory) (
7657 void** handler /* out */,
7658 const char* jobId,
7659 const char* transactionUid,
7660 const char* const* sopClassUids,
7661 const char* const* sopInstanceUids,
7662 uint32_t countInstances,
7663 const char* remoteAet,
7664 const char* calledAet);
7665
7666
7667 /**
7668 * @brief Callback to free one storage commitment SCP handler.
7669 *
7670 * Signature of a callback function that releases the resources
7671 * allocated by the factory of the storage commitment SCP. The
7672 * handler is the return value of a previous call to the
7673 * OrthancPluginStorageCommitmentFactory() callback.
7674 *
7675 * @param handler The handler object to be destructed.
7676 * @ingroup DicomCallbacks
7677 **/
7678 typedef void (*OrthancPluginStorageCommitmentDestructor) (void* handler);
7679
7680
7681 /**
7682 * @brief Callback to get the status of one DICOM instance in the
7683 * storage commitment SCP.
7684 *
7685 * Signature of a callback function that is successively invoked for
7686 * each DICOM instance that is queried by the remote storage
7687 * commitment SCU. The function must be tought of as a method of
7688 * the handler object that was created by a previous call to the
7689 * OrthancPluginStorageCommitmentFactory() callback. After each call
7690 * to this method, the progress of the associated Orthanc job is
7691 * updated.
7692 *
7693 * @param target Output variable where to put the status for the queried instance.
7694 * @param handler The handler object associated with this storage commitment request.
7695 * @param sopClassUid The SOP class UID (0008,0016) of interest.
7696 * @param sopInstanceUid The SOP instance UID (0008,0018) of interest.
7697 * @ingroup DicomCallbacks
7698 **/
7699 typedef OrthancPluginErrorCode (*OrthancPluginStorageCommitmentLookup) (
7700 OrthancPluginStorageCommitmentFailureReason* target,
7701 void* handler,
7702 const char* sopClassUid,
7703 const char* sopInstanceUid);
7704
7705
7706 typedef struct
7707 {
7708 OrthancPluginStorageCommitmentFactory factory;
7709 OrthancPluginStorageCommitmentDestructor destructor;
7710 OrthancPluginStorageCommitmentLookup lookup;
7711 } _OrthancPluginRegisterStorageCommitmentScpCallback;
7712
7713 /**
7714 * @brief Register a callback to handle incoming requests to the storage commitment SCP.
7715 *
7716 * This function registers a callback to handle storage commitment SCP requests.
7717 *
7718 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7719 * @param factory Factory function that creates the handler object
7720 * for incoming storage commitment requests.
7721 * @param destructor Destructor function to destroy the handler object.
7722 * @param lookup Callback method to get the status of one DICOM instance.
7723 * @return 0 if success, other value if error.
7724 * @ingroup DicomCallbacks
7725 **/
7726 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterStorageCommitmentScpCallback(
7727 OrthancPluginContext* context,
7728 OrthancPluginStorageCommitmentFactory factory,
7729 OrthancPluginStorageCommitmentDestructor destructor,
7730 OrthancPluginStorageCommitmentLookup lookup)
7731 {
7732 _OrthancPluginRegisterStorageCommitmentScpCallback params;
7733 params.factory = factory;
7734 params.destructor = destructor;
7735 params.lookup = lookup;
7736 return context->InvokeService(context, _OrthancPluginService_RegisterStorageCommitmentScpCallback, &params);
7737 }
7738
7739
7740
7741 /**
7742 * @brief Callback to filter incoming DICOM instances received by Orthanc.
7743 *
7744 * Signature of a callback function that is triggered whenever
7745 * Orthanc receives a new DICOM instance (e.g. through REST API or
7746 * DICOM protocol), and that answers whether this DICOM instance
7747 * should be accepted or discarded by Orthanc.
7748 *
7749 * Note that the metadata information is not available
7750 * (i.e. GetInstanceMetadata() should not be used on "instance").
7751 *
7752 * @warning Your callback function will be called synchronously with
7753 * the core of Orthanc. This implies that deadlocks might emerge if
7754 * you call other core primitives of Orthanc in your callback (such
7755 * deadlocks are particularly visible in the presence of other plugins
7756 * or Lua scripts). It is thus strongly advised to avoid any call to
7757 * the REST API of Orthanc in the callback. If you have to call
7758 * other primitives of Orthanc, you should make these calls in a
7759 * separate thread, passing the pending events to be processed
7760 * through a message queue.
7761 *
7762 * @param instance The received DICOM instance.
7763 * @return 0 to discard the instance, 1 to store the instance, -1 if error.
7764 * @ingroup Callback
7765 **/
7766 typedef int32_t (*OrthancPluginIncomingDicomInstanceFilter) (
7767 const OrthancPluginDicomInstance* instance);
7768
7769
7770 typedef struct
7771 {
7772 OrthancPluginIncomingDicomInstanceFilter callback;
7773 } _OrthancPluginIncomingDicomInstanceFilter;
7774
7775 /**
7776 * @brief Register a callback to filter incoming DICOM instances.
7777 *
7778 * This function registers a custom callback to filter incoming
7779 * DICOM instances received by Orthanc (either through the REST API
7780 * or through the DICOM protocol).
7781 *
7782 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7783 * @param callback The callback.
7784 * @return 0 if success, other value if error.
7785 * @ingroup Callbacks
7786 **/
7787 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingDicomInstanceFilter(
7788 OrthancPluginContext* context,
7789 OrthancPluginIncomingDicomInstanceFilter callback)
7790 {
7791 _OrthancPluginIncomingDicomInstanceFilter params;
7792 params.callback = callback;
7793
7794 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingDicomInstanceFilter, &params);
7795 }
7796
7797
7798 /**
7799 * @brief Callback to filter incoming DICOM instances received by
7800 * Orthanc through C-STORE.
7801 *
7802 * Signature of a callback function that is triggered whenever
7803 * Orthanc receives a new DICOM instance using DICOM C-STORE, and
7804 * that answers whether this DICOM instance should be accepted or
7805 * discarded by Orthanc. If the instance is discarded, the callback
7806 * can specify the DIMSE error code answered by the Orthanc C-STORE
7807 * SCP.
7808 *
7809 * Note that the metadata information is not available
7810 * (i.e. GetInstanceMetadata() should not be used on "instance").
7811 *
7812 * @warning Your callback function will be called synchronously with
7813 * the core of Orthanc. This implies that deadlocks might emerge if
7814 * you call other core primitives of Orthanc in your callback (such
7815 * deadlocks are particularly visible in the presence of other plugins
7816 * or Lua scripts). It is thus strongly advised to avoid any call to
7817 * the REST API of Orthanc in the callback. If you have to call
7818 * other primitives of Orthanc, you should make these calls in a
7819 * separate thread, passing the pending events to be processed
7820 * through a message queue.
7821 *
7822 * @param dimseStatus If the DICOM instance is discarded,
7823 * DIMSE status to be sent by the C-STORE SCP of Orthanc
7824 * @param instance The received DICOM instance.
7825 * @return 0 to discard the instance, 1 to store the instance, -1 if error.
7826 * @ingroup Callback
7827 **/
7828 typedef int32_t (*OrthancPluginIncomingCStoreInstanceFilter) (
7829 uint16_t* dimseStatus /* out */,
7830 const OrthancPluginDicomInstance* instance);
7831
7832
7833 typedef struct
7834 {
7835 OrthancPluginIncomingCStoreInstanceFilter callback;
7836 } _OrthancPluginIncomingCStoreInstanceFilter;
7837
7838 /**
7839 * @brief Register a callback to filter incoming DICOM instances
7840 * received by Orthanc through C-STORE.
7841 *
7842 * This function registers a custom callback to filter incoming
7843 * DICOM instances received by Orthanc through the DICOM protocol.
7844 *
7845 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7846 * @param callback The callback.
7847 * @return 0 if success, other value if error.
7848 * @ingroup Callbacks
7849 **/
7850 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterIncomingCStoreInstanceFilter(
7851 OrthancPluginContext* context,
7852 OrthancPluginIncomingCStoreInstanceFilter callback)
7853 {
7854 _OrthancPluginIncomingCStoreInstanceFilter params;
7855 params.callback = callback;
7856
7857 return context->InvokeService(context, _OrthancPluginService_RegisterIncomingCStoreInstanceFilter, &params);
7858 }
7859
7860 /**
7861 * @brief Callback to keep/discard/modify a DICOM instance received
7862 * by Orthanc from any source (C-STORE or REST API)
7863 *
7864 * Signature of a callback function that is triggered whenever
7865 * Orthanc receives a new DICOM instance (through DICOM protocol or
7866 * REST API), and that specifies an action to be applied to this
7867 * newly received instance. The instance can be kept as it is, can
7868 * be modified by the plugin, or can be discarded.
7869 *
7870 * This callback is invoked immediately after reception, i.e. before
7871 * transcoding and before filtering
7872 * (cf. OrthancPluginRegisterIncomingDicomInstanceFilter()).
7873 *
7874 * @warning Your callback function will be called synchronously with
7875 * the core of Orthanc. This implies that deadlocks might emerge if
7876 * you call other core primitives of Orthanc in your callback (such
7877 * deadlocks are particularly visible in the presence of other plugins
7878 * or Lua scripts). It is thus strongly advised to avoid any call to
7879 * the REST API of Orthanc in the callback. If you have to call
7880 * other primitives of Orthanc, you should make these calls in a
7881 * separate thread, passing the pending events to be processed
7882 * through a message queue.
7883 *
7884 * @param modifiedDicomBuffer A buffer containing the modified DICOM (output).
7885 * This buffer must be allocated using OrthancPluginCreateMemoryBuffer64()
7886 * and will be freed by the Orthanc core.
7887 * @param receivedDicomBuffer A buffer containing the received DICOM (input).
7888 * @param receivedDicomBufferSize The size of the received DICOM (input).
7889 * @param origin The origin of the DICOM instance (input).
7890 * @return `OrthancPluginReceivedInstanceAction_KeepAsIs` to accept the instance as is,<br/>
7891 * `OrthancPluginReceivedInstanceAction_Modify` to store the modified DICOM contained in `modifiedDicomBuffer`,<br/>
7892 * `OrthancPluginReceivedInstanceAction_Discard` to tell Orthanc to discard the instance.
7893 * @ingroup Callback
7894 **/
7895 typedef OrthancPluginReceivedInstanceAction (*OrthancPluginReceivedInstanceCallback) (
7896 OrthancPluginMemoryBuffer64* modifiedDicomBuffer,
7897 const void* receivedDicomBuffer,
7898 uint64_t receivedDicomBufferSize,
7899 OrthancPluginInstanceOrigin origin);
7900
7901
7902 typedef struct
7903 {
7904 OrthancPluginReceivedInstanceCallback callback;
7905 } _OrthancPluginReceivedInstanceCallback;
7906
7907 /**
7908 * @brief Register a callback to keep/discard/modify a DICOM instance received
7909 * by Orthanc from any source (C-STORE or REST API)
7910 *
7911 * This function registers a custom callback to keep/discard/modify
7912 * incoming DICOM instances received by Orthanc from any source
7913 * (C-STORE or REST API).
7914 *
7915 * @warning Contrarily to
7916 * OrthancPluginRegisterIncomingCStoreInstanceFilter() and
7917 * OrthancPluginRegisterIncomingDicomInstanceFilter() that can be
7918 * called by multiple plugins,
7919 * OrthancPluginRegisterReceivedInstanceCallback() can only be used
7920 * by one single plugin.
7921 *
7922 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7923 * @param callback The callback.
7924 * @return 0 if success, other value if error.
7925 * @ingroup Callbacks
7926 **/
7927 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterReceivedInstanceCallback(
7928 OrthancPluginContext* context,
7929 OrthancPluginReceivedInstanceCallback callback)
7930 {
7931 _OrthancPluginReceivedInstanceCallback params;
7932 params.callback = callback;
7933
7934 return context->InvokeService(context, _OrthancPluginService_RegisterReceivedInstanceCallback, &params);
7935 }
7936
7937 /**
7938 * @brief Get the transfer syntax of a DICOM file.
7939 *
7940 * This function returns a pointer to a newly created string that
7941 * contains the transfer syntax UID of the DICOM instance. The empty
7942 * string might be returned if this information is unknown.
7943 *
7944 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7945 * @param instance The instance of interest.
7946 * @return The NULL value in case of error, or a string containing the
7947 * transfer syntax UID. This string must be freed by OrthancPluginFreeString().
7948 * @ingroup DicomInstance
7949 **/
7950 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceTransferSyntaxUid(
7951 OrthancPluginContext* context,
7952 const OrthancPluginDicomInstance* instance)
7953 {
7954 char* result;
7955
7956 _OrthancPluginAccessDicomInstance params;
7957 memset(&params, 0, sizeof(params));
7958 params.resultStringToFree = &result;
7959 params.instance = instance;
7960
7961 if (context->InvokeService(context, _OrthancPluginService_GetInstanceTransferSyntaxUid, &params) != OrthancPluginErrorCode_Success)
7962 {
7963 /* Error */
7964 return NULL;
7965 }
7966 else
7967 {
7968 return result;
7969 }
7970 }
7971
7972
7973 /**
7974 * @brief Check whether the DICOM file has pixel data.
7975 *
7976 * This function returns a Boolean value indicating whether the
7977 * DICOM instance contains the pixel data (7FE0,0010) tag.
7978 *
7979 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
7980 * @param instance The instance of interest.
7981 * @return "1" if the DICOM instance contains pixel data, or "0" if
7982 * the tag is missing, or "-1" in the case of an error.
7983 * @ingroup DicomInstance
7984 **/
7985 ORTHANC_PLUGIN_INLINE int32_t OrthancPluginHasInstancePixelData(
7986 OrthancPluginContext* context,
7987 const OrthancPluginDicomInstance* instance)
7988 {
7989 int64_t hasPixelData;
7990
7991 _OrthancPluginAccessDicomInstance params;
7992 memset(&params, 0, sizeof(params));
7993 params.resultInt64 = &hasPixelData;
7994 params.instance = instance;
7995
7996 if (context->InvokeService(context, _OrthancPluginService_HasInstancePixelData, &params) != OrthancPluginErrorCode_Success ||
7997 hasPixelData < 0 ||
7998 hasPixelData > 1)
7999 {
8000 /* Error */
8001 return -1;
8002 }
8003 else
8004 {
8005 return (hasPixelData != 0);
8006 }
8007 }
8008
8009
8010
8011
8012
8013
8014 typedef struct
8015 {
8016 OrthancPluginDicomInstance** target;
8017 const void* buffer;
8018 uint32_t size;
8019 const char* transferSyntax;
8020 } _OrthancPluginCreateDicomInstance;
8021
8022 /**
8023 * @brief Parse a DICOM instance.
8024 *
8025 * This function parses a memory buffer that contains a DICOM
8026 * file. The function returns a new pointer to a data structure that
8027 * is managed by the Orthanc core.
8028 *
8029 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8030 * @param buffer The memory buffer containing the DICOM instance.
8031 * @param size The size of the memory buffer.
8032 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance().
8033 * @ingroup DicomInstance
8034 **/
8035 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginCreateDicomInstance(
8036 OrthancPluginContext* context,
8037 const void* buffer,
8038 uint32_t size)
8039 {
8040 OrthancPluginDicomInstance* target = NULL;
8041
8042 _OrthancPluginCreateDicomInstance params;
8043 params.target = &target;
8044 params.buffer = buffer;
8045 params.size = size;
8046
8047 if (context->InvokeService(context, _OrthancPluginService_CreateDicomInstance, &params) != OrthancPluginErrorCode_Success)
8048 {
8049 /* Error */
8050 return NULL;
8051 }
8052 else
8053 {
8054 return target;
8055 }
8056 }
8057
8058 typedef struct
8059 {
8060 OrthancPluginDicomInstance* dicom;
8061 } _OrthancPluginFreeDicomInstance;
8062
8063 /**
8064 * @brief Free a DICOM instance.
8065 *
8066 * This function frees a DICOM instance that was parsed using
8067 * OrthancPluginCreateDicomInstance().
8068 *
8069 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8070 * @param dicom The DICOM instance.
8071 * @ingroup DicomInstance
8072 **/
8073 ORTHANC_PLUGIN_INLINE void OrthancPluginFreeDicomInstance(
8074 OrthancPluginContext* context,
8075 OrthancPluginDicomInstance* dicom)
8076 {
8077 _OrthancPluginFreeDicomInstance params;
8078 params.dicom = dicom;
8079
8080 context->InvokeService(context, _OrthancPluginService_FreeDicomInstance, &params);
8081 }
8082
8083
8084 typedef struct
8085 {
8086 uint32_t* targetUint32;
8087 OrthancPluginMemoryBuffer* targetBuffer;
8088 OrthancPluginImage** targetImage;
8089 char** targetStringToFree;
8090 const OrthancPluginDicomInstance* instance;
8091 uint32_t frameIndex;
8092 OrthancPluginDicomToJsonFormat format;
8093 OrthancPluginDicomToJsonFlags flags;
8094 uint32_t maxStringLength;
8095 OrthancPluginDicomWebBinaryCallback2 dicomWebCallback;
8096 void* dicomWebPayload;
8097 } _OrthancPluginAccessDicomInstance2;
8098
8099 /**
8100 * @brief Get the number of frames in a DICOM instance.
8101 *
8102 * This function returns the number of frames that are part of a
8103 * DICOM image managed by the Orthanc core.
8104 *
8105 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8106 * @param instance The instance of interest.
8107 * @return The number of frames (will be zero in the case of an error).
8108 * @ingroup DicomInstance
8109 **/
8110 ORTHANC_PLUGIN_INLINE uint32_t OrthancPluginGetInstanceFramesCount(
8111 OrthancPluginContext* context,
8112 const OrthancPluginDicomInstance* instance)
8113 {
8114 uint32_t count;
8115
8116 _OrthancPluginAccessDicomInstance2 params;
8117 memset(&params, 0, sizeof(params));
8118 params.targetUint32 = &count;
8119 params.instance = instance;
8120
8121 if (context->InvokeService(context, _OrthancPluginService_GetInstanceFramesCount, &params) != OrthancPluginErrorCode_Success)
8122 {
8123 /* Error */
8124 return 0;
8125 }
8126 else
8127 {
8128 return count;
8129 }
8130 }
8131
8132
8133 /**
8134 * @brief Get the raw content of a frame in a DICOM instance.
8135 *
8136 * This function returns a memory buffer containing the raw content
8137 * of a frame in a DICOM instance that is managed by the Orthanc
8138 * core. This is notably useful for compressed transfer syntaxes, as
8139 * it gives access to the embedded files (such as JPEG, JPEG-LS or
8140 * JPEG2k). The Orthanc core transparently reassembles the fragments
8141 * to extract the raw frame.
8142 *
8143 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8144 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8145 * @param instance The instance of interest.
8146 * @param frameIndex The index of the frame of interest.
8147 * @return 0 if success, or the error code if failure.
8148 * @ingroup DicomInstance
8149 **/
8150 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginGetInstanceRawFrame(
8151 OrthancPluginContext* context,
8152 OrthancPluginMemoryBuffer* target,
8153 const OrthancPluginDicomInstance* instance,
8154 uint32_t frameIndex)
8155 {
8156 _OrthancPluginAccessDicomInstance2 params;
8157 memset(&params, 0, sizeof(params));
8158 params.targetBuffer = target;
8159 params.instance = instance;
8160 params.frameIndex = frameIndex;
8161
8162 return context->InvokeService(context, _OrthancPluginService_GetInstanceRawFrame, &params);
8163 }
8164
8165
8166 /**
8167 * @brief Decode one frame from a DICOM instance.
8168 *
8169 * This function decodes one frame of a DICOM image that is managed
8170 * by the Orthanc core.
8171 *
8172 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8173 * @param instance The instance of interest.
8174 * @param frameIndex The index of the frame of interest.
8175 * @return The uncompressed image. It must be freed with OrthancPluginFreeImage().
8176 * @ingroup DicomInstance
8177 **/
8178 ORTHANC_PLUGIN_INLINE OrthancPluginImage* OrthancPluginGetInstanceDecodedFrame(
8179 OrthancPluginContext* context,
8180 const OrthancPluginDicomInstance* instance,
8181 uint32_t frameIndex)
8182 {
8183 OrthancPluginImage* target = NULL;
8184
8185 _OrthancPluginAccessDicomInstance2 params;
8186 memset(&params, 0, sizeof(params));
8187 params.targetImage = &target;
8188 params.instance = instance;
8189 params.frameIndex = frameIndex;
8190
8191 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDecodedFrame, &params) != OrthancPluginErrorCode_Success)
8192 {
8193 return NULL;
8194 }
8195 else
8196 {
8197 return target;
8198 }
8199 }
8200
8201
8202 /**
8203 * @brief Parse and transcode a DICOM instance.
8204 *
8205 * This function parses a memory buffer that contains a DICOM file,
8206 * then transcodes it to the given transfer syntax. The function
8207 * returns a new pointer to a data structure that is managed by the
8208 * Orthanc core.
8209 *
8210 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8211 * @param buffer The memory buffer containing the DICOM instance.
8212 * @param size The size of the memory buffer.
8213 * @param transferSyntax The transfer syntax UID for the transcoding.
8214 * @return The newly allocated DICOM instance. It must be freed with OrthancPluginFreeDicomInstance().
8215 * @ingroup DicomInstance
8216 **/
8217 ORTHANC_PLUGIN_INLINE OrthancPluginDicomInstance* OrthancPluginTranscodeDicomInstance(
8218 OrthancPluginContext* context,
8219 const void* buffer,
8220 uint32_t size,
8221 const char* transferSyntax)
8222 {
8223 OrthancPluginDicomInstance* target = NULL;
8224
8225 _OrthancPluginCreateDicomInstance params;
8226 params.target = &target;
8227 params.buffer = buffer;
8228 params.size = size;
8229 params.transferSyntax = transferSyntax;
8230
8231 if (context->InvokeService(context, _OrthancPluginService_TranscodeDicomInstance, &params) != OrthancPluginErrorCode_Success)
8232 {
8233 /* Error */
8234 return NULL;
8235 }
8236 else
8237 {
8238 return target;
8239 }
8240 }
8241
8242 /**
8243 * @brief Writes a DICOM instance to a memory buffer.
8244 *
8245 * This function returns a memory buffer containing the
8246 * serialization of a DICOM instance that is managed by the Orthanc
8247 * core.
8248 *
8249 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8250 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8251 * @param instance The instance of interest.
8252 * @return 0 if success, or the error code if failure.
8253 * @ingroup DicomInstance
8254 **/
8255 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginSerializeDicomInstance(
8256 OrthancPluginContext* context,
8257 OrthancPluginMemoryBuffer* target,
8258 const OrthancPluginDicomInstance* instance)
8259 {
8260 _OrthancPluginAccessDicomInstance2 params;
8261 memset(&params, 0, sizeof(params));
8262 params.targetBuffer = target;
8263 params.instance = instance;
8264
8265 return context->InvokeService(context, _OrthancPluginService_SerializeDicomInstance, &params);
8266 }
8267
8268
8269 /**
8270 * @brief Format a DICOM memory buffer as a JSON string.
8271 *
8272 * This function takes as DICOM instance managed by the Orthanc
8273 * core, and outputs a JSON string representing the tags of this
8274 * DICOM file.
8275 *
8276 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8277 * @param instance The DICOM instance of interest.
8278 * @param format The output format.
8279 * @param flags Flags governing the output.
8280 * @param maxStringLength The maximum length of a field. Too long fields will
8281 * be output as "null". The 0 value means no maximum length.
8282 * @return The NULL value if the case of an error, or the JSON
8283 * string. This string must be freed by OrthancPluginFreeString().
8284 * @ingroup DicomInstance
8285 * @see OrthancPluginDicomBufferToJson
8286 **/
8287 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceAdvancedJson(
8288 OrthancPluginContext* context,
8289 const OrthancPluginDicomInstance* instance,
8290 OrthancPluginDicomToJsonFormat format,
8291 OrthancPluginDicomToJsonFlags flags,
8292 uint32_t maxStringLength)
8293 {
8294 char* result = NULL;
8295
8296 _OrthancPluginAccessDicomInstance2 params;
8297 memset(&params, 0, sizeof(params));
8298 params.targetStringToFree = &result;
8299 params.instance = instance;
8300 params.format = format;
8301 params.flags = flags;
8302 params.maxStringLength = maxStringLength;
8303
8304 if (context->InvokeService(context, _OrthancPluginService_GetInstanceAdvancedJson, &params) != OrthancPluginErrorCode_Success)
8305 {
8306 /* Error */
8307 return NULL;
8308 }
8309 else
8310 {
8311 return result;
8312 }
8313 }
8314
8315
8316 /**
8317 * @brief Convert a DICOM instance to DICOMweb JSON.
8318 *
8319 * This function converts a DICOM instance that is managed by the
8320 * Orthanc core, into its DICOMweb JSON representation.
8321 *
8322 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8323 * @param instance The DICOM instance of interest.
8324 * @param callback Callback to set the value of the binary tags.
8325 * @param payload User payload.
8326 * @return The NULL value in case of error, or the JSON document. This string must
8327 * be freed by OrthancPluginFreeString().
8328 * @ingroup DicomInstance
8329 **/
8330 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebJson(
8331 OrthancPluginContext* context,
8332 const OrthancPluginDicomInstance* instance,
8333 OrthancPluginDicomWebBinaryCallback2 callback,
8334 void* payload)
8335 {
8336 char* target = NULL;
8337
8338 _OrthancPluginAccessDicomInstance2 params;
8339 params.targetStringToFree = &target;
8340 params.instance = instance;
8341 params.dicomWebCallback = callback;
8342 params.dicomWebPayload = payload;
8343
8344 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebJson, &params) != OrthancPluginErrorCode_Success)
8345 {
8346 /* Error */
8347 return NULL;
8348 }
8349 else
8350 {
8351 return target;
8352 }
8353 }
8354
8355
8356 /**
8357 * @brief Convert a DICOM instance to DICOMweb XML.
8358 *
8359 * This function converts a DICOM instance that is managed by the
8360 * Orthanc core, into its DICOMweb XML representation.
8361 *
8362 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8363 * @param instance The DICOM instance of interest.
8364 * @param callback Callback to set the value of the binary tags.
8365 * @param payload User payload.
8366 * @return The NULL value in case of error, or the XML document. This string must
8367 * be freed by OrthancPluginFreeString().
8368 * @ingroup DicomInstance
8369 **/
8370 ORTHANC_PLUGIN_INLINE char* OrthancPluginGetInstanceDicomWebXml(
8371 OrthancPluginContext* context,
8372 const OrthancPluginDicomInstance* instance,
8373 OrthancPluginDicomWebBinaryCallback2 callback,
8374 void* payload)
8375 {
8376 char* target = NULL;
8377
8378 _OrthancPluginAccessDicomInstance2 params;
8379 params.targetStringToFree = &target;
8380 params.instance = instance;
8381 params.dicomWebCallback = callback;
8382 params.dicomWebPayload = payload;
8383
8384 if (context->InvokeService(context, _OrthancPluginService_GetInstanceDicomWebXml, &params) != OrthancPluginErrorCode_Success)
8385 {
8386 /* Error */
8387 return NULL;
8388 }
8389 else
8390 {
8391 return target;
8392 }
8393 }
8394
8395
8396
8397 /**
8398 * @brief Signature of a callback function to transcode a DICOM instance.
8399 * @param transcoded Target memory buffer. It must be allocated by the
8400 * plugin using OrthancPluginCreateMemoryBuffer().
8401 * @param buffer Memory buffer containing the source DICOM instance.
8402 * @param size Size of the source memory buffer.
8403 * @param allowedSyntaxes A C array of possible transfer syntaxes UIDs for the
8404 * result of the transcoding. The plugin must choose by itself the
8405 * transfer syntax that will be used for the resulting DICOM image.
8406 * @param countSyntaxes The number of transfer syntaxes that are contained
8407 * in the "allowedSyntaxes" array.
8408 * @param allowNewSopInstanceUid Whether the transcoding plugin can select
8409 * a transfer syntax that will change the SOP instance UID (or, in other
8410 * terms, whether the plugin can transcode using lossy compression).
8411 * @return 0 if success (i.e. image successfully transcoded and stored into
8412 * "transcoded"), or the error code if failure.
8413 * @ingroup Callbacks
8414 **/
8415 typedef OrthancPluginErrorCode (*OrthancPluginTranscoderCallback) (
8416 OrthancPluginMemoryBuffer* transcoded /* out */,
8417 const void* buffer,
8418 uint64_t size,
8419 const char* const* allowedSyntaxes,
8420 uint32_t countSyntaxes,
8421 uint8_t allowNewSopInstanceUid);
8422
8423
8424 typedef struct
8425 {
8426 OrthancPluginTranscoderCallback callback;
8427 } _OrthancPluginTranscoderCallback;
8428
8429 /**
8430 * @brief Register a callback to handle the transcoding of DICOM images.
8431 *
8432 * This function registers a custom callback to transcode DICOM
8433 * images, extending the built-in transcoder of Orthanc that uses
8434 * DCMTK. The exact behavior is affected by the configuration option
8435 * "BuiltinDecoderTranscoderOrder" of Orthanc.
8436 *
8437 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8438 * @param callback The callback.
8439 * @return 0 if success, other value if error.
8440 * @ingroup Callbacks
8441 **/
8442 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginRegisterTranscoderCallback(
8443 OrthancPluginContext* context,
8444 OrthancPluginTranscoderCallback callback)
8445 {
8446 _OrthancPluginTranscoderCallback params;
8447 params.callback = callback;
8448
8449 return context->InvokeService(context, _OrthancPluginService_RegisterTranscoderCallback, &params);
8450 }
8451
8452
8453
8454 typedef struct
8455 {
8456 OrthancPluginMemoryBuffer* target;
8457 uint32_t size;
8458 } _OrthancPluginCreateMemoryBuffer;
8459
8460 /**
8461 * @brief Create a 32-bit memory buffer.
8462 *
8463 * This function creates a memory buffer that is managed by the
8464 * Orthanc core. The main use case of this function is for plugins
8465 * that act as DICOM transcoders.
8466 *
8467 * Your plugin should never call "free()" on the resulting memory
8468 * buffer, as the C library that is used by the plugin is in general
8469 * not the same as the one used by the Orthanc core.
8470 *
8471 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8472 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8473 * @param size Size of the memory buffer to be created.
8474 * @return 0 if success, or the error code if failure.
8475 * @ingroup Toolbox
8476 **/
8477 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateMemoryBuffer(
8478 OrthancPluginContext* context,
8479 OrthancPluginMemoryBuffer* target,
8480 uint32_t size)
8481 {
8482 _OrthancPluginCreateMemoryBuffer params;
8483 params.target = target;
8484 params.size = size;
8485
8486 return context->InvokeService(context, _OrthancPluginService_CreateMemoryBuffer, &params);
8487 }
8488
8489
8490 /**
8491 * @brief Generate a token to grant full access to the REST API of Orthanc
8492 *
8493 * This function generates a token that can be set in the HTTP
8494 * header "Authorization" so as to grant full access to the REST API
8495 * of Orthanc using an external HTTP client. Using this function
8496 * avoids the need of adding a separate user in the
8497 * "RegisteredUsers" configuration of Orthanc, which eases
8498 * deployments.
8499 *
8500 * This feature is notably useful in multiprocess scenarios, where a
8501 * subprocess created by a plugin has no access to the
8502 * "OrthancPluginContext", and thus cannot call
8503 * "OrthancPluginRestApi[Get|Post|Put|Delete]()".
8504 *
8505 * This situation is frequently encountered in Python plugins, where
8506 * the "multiprocessing" package can be used to bypass the Global
8507 * Interpreter Lock (GIL) and thus to improve performance and
8508 * concurrency.
8509 *
8510 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8511 * @return The authorization token, or NULL value in the case of an error.
8512 * This string must be freed by OrthancPluginFreeString().
8513 * @ingroup Orthanc
8514 **/
8515 ORTHANC_PLUGIN_INLINE char* OrthancPluginGenerateRestApiAuthorizationToken(
8516 OrthancPluginContext* context)
8517 {
8518 char* result;
8519
8520 _OrthancPluginRetrieveDynamicString params;
8521 params.result = &result;
8522 params.argument = NULL;
8523
8524 if (context->InvokeService(context, _OrthancPluginService_GenerateRestApiAuthorizationToken,
8525 &params) != OrthancPluginErrorCode_Success)
8526 {
8527 /* Error */
8528 return NULL;
8529 }
8530 else
8531 {
8532 return result;
8533 }
8534 }
8535
8536
8537
8538 typedef struct
8539 {
8540 OrthancPluginMemoryBuffer64* target;
8541 uint64_t size;
8542 } _OrthancPluginCreateMemoryBuffer64;
8543
8544 /**
8545 * @brief Create a 64-bit memory buffer.
8546 *
8547 * This function creates a 64-bit memory buffer that is managed by
8548 * the Orthanc core. The main use case of this function is for
8549 * plugins that read files from the storage area.
8550 *
8551 * Your plugin should never call "free()" on the resulting memory
8552 * buffer, as the C library that is used by the plugin is in general
8553 * not the same as the one used by the Orthanc core.
8554 *
8555 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8556 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8557 * @param size Size of the memory buffer to be created.
8558 * @return 0 if success, or the error code if failure.
8559 * @ingroup Toolbox
8560 **/
8561 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateMemoryBuffer64(
8562 OrthancPluginContext* context,
8563 OrthancPluginMemoryBuffer64* target,
8564 uint64_t size)
8565 {
8566 _OrthancPluginCreateMemoryBuffer64 params;
8567 params.target = target;
8568 params.size = size;
8569
8570 return context->InvokeService(context, _OrthancPluginService_CreateMemoryBuffer64, &params);
8571 }
8572
8573
8574 typedef struct
8575 {
8576 OrthancPluginStorageCreate create;
8577 OrthancPluginStorageReadWhole readWhole;
8578 OrthancPluginStorageReadRange readRange;
8579 OrthancPluginStorageRemove remove;
8580 } _OrthancPluginRegisterStorageArea2;
8581
8582 /**
8583 * @brief Register a custom storage area, with support for range request.
8584 *
8585 * This function registers a custom storage area, to replace the
8586 * built-in way Orthanc stores its files on the filesystem. This
8587 * function must be called during the initialization of the plugin,
8588 * i.e. inside the OrthancPluginInitialize() public function.
8589 *
8590 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8591 * @param create The callback function to store a file on the custom storage area.
8592 * @param readWhole The callback function to read a whole file from the custom storage area.
8593 * @param readRange The callback function to read some range of a file from the custom storage area.
8594 * If this feature is not supported by the plugin, this value can be set to NULL.
8595 * @param remove The callback function to remove a file from the custom storage area.
8596 * @ingroup Callbacks
8597 **/
8598 ORTHANC_PLUGIN_INLINE void OrthancPluginRegisterStorageArea2(
8599 OrthancPluginContext* context,
8600 OrthancPluginStorageCreate create,
8601 OrthancPluginStorageReadWhole readWhole,
8602 OrthancPluginStorageReadRange readRange,
8603 OrthancPluginStorageRemove remove)
8604 {
8605 _OrthancPluginRegisterStorageArea2 params;
8606 params.create = create;
8607 params.readWhole = readWhole;
8608 params.readRange = readRange;
8609 params.remove = remove;
8610 context->InvokeService(context, _OrthancPluginService_RegisterStorageArea2, &params);
8611 }
8612
8613
8614
8615 typedef struct
8616 {
8617 _OrthancPluginCreateDicom createDicom;
8618 const char* privateCreator;
8619 } _OrthancPluginCreateDicom2;
8620
8621 /**
8622 * @brief Create a DICOM instance from a JSON string and an image, with a private creator.
8623 *
8624 * This function takes as input a string containing a JSON file
8625 * describing the content of a DICOM instance. As an output, it
8626 * writes the corresponding DICOM instance to a newly allocated
8627 * memory buffer. Additionally, an image to be encoded within the
8628 * DICOM instance can also be provided.
8629 *
8630 * Contrarily to the function OrthancPluginCreateDicom(), this
8631 * function can be explicitly provided with a private creator.
8632 *
8633 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8634 * @param target The target memory buffer. It must be freed with OrthancPluginFreeMemoryBuffer().
8635 * @param json The input JSON file.
8636 * @param pixelData The image. Can be NULL, if the pixel data is encoded inside the JSON with the data URI scheme.
8637 * @param flags Flags governing the output.
8638 * @param privateCreator The private creator to be used for the private DICOM tags.
8639 * Check out the global configuration option "Dictionary" of Orthanc.
8640 * @return 0 if success, other value if error.
8641 * @ingroup Toolbox
8642 * @see OrthancPluginCreateDicom
8643 * @see OrthancPluginDicomBufferToJson
8644 **/
8645 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCreateDicom2(
8646 OrthancPluginContext* context,
8647 OrthancPluginMemoryBuffer* target,
8648 const char* json,
8649 const OrthancPluginImage* pixelData,
8650 OrthancPluginCreateDicomFlags flags,
8651 const char* privateCreator)
8652 {
8653 _OrthancPluginCreateDicom2 params;
8654 params.createDicom.target = target;
8655 params.createDicom.json = json;
8656 params.createDicom.pixelData = pixelData;
8657 params.createDicom.flags = flags;
8658 params.privateCreator = privateCreator;
8659
8660 return context->InvokeService(context, _OrthancPluginService_CreateDicom2, &params);
8661 }
8662
8663
8664
8665
8666
8667
8668 typedef struct
8669 {
8670 OrthancPluginMemoryBuffer* answerBody;
8671 OrthancPluginMemoryBuffer* answerHeaders;
8672 uint16_t* httpStatus;
8673 OrthancPluginHttpMethod method;
8674 const char* uri;
8675 uint32_t headersCount;
8676 const char* const* headersKeys;
8677 const char* const* headersValues;
8678 const void* body;
8679 uint32_t bodySize;
8680 uint8_t afterPlugins;
8681 } _OrthancPluginCallRestApi;
8682
8683 /**
8684 * @brief Call the REST API of Orthanc with full flexibility.
8685 *
8686 * Make a call to the given URI in the REST API of Orthanc. The
8687 * result to the query is stored into a newly allocated memory
8688 * buffer. This function is always granted full access to the REST
8689 * API (no credentials, nor security token is needed).
8690 *
8691 * @param context The Orthanc plugin context, as received by OrthancPluginInitialize().
8692 * @param answerBody The target memory buffer (out argument).
8693 * It must be freed with OrthancPluginFreeMemoryBuffer().
8694 * The value of this argument is ignored if the HTTP method is DELETE.
8695 * @param answerHeaders The target memory buffer for the HTTP headers in the answer (out argument).
8696 * The answer headers are formatted as a JSON object (associative array).
8697 * The buffer must be freed with OrthancPluginFreeMemoryBuffer().
8698 * This argument can be set to NULL if the plugin has no interest in the answer HTTP headers.
8699 * @param httpStatus The HTTP status after the execution of the request (out argument).
8700 * @param method HTTP method to be used.
8701 * @param uri The URI of interest.
8702 * @param headersCount The number of HTTP headers.
8703 * @param headersKeys Array containing the keys of the HTTP headers (can be <tt>NULL</tt> if no header).
8704 * @param headersValues Array containing the values of the HTTP headers (can be <tt>NULL</tt> if no header).
8705 * @param body The HTTP body for a POST or PUT request.
8706 * @param bodySize The size of the body.
8707 * @param afterPlugins If 0, the built-in API of Orthanc is used.
8708 * If 1, the API is tainted by the plugins.
8709 * @return 0 if success, or the error code if failure.
8710 * @see OrthancPluginRestApiGet2, OrthancPluginRestApiPost, OrthancPluginRestApiPut, OrthancPluginRestApiDelete
8711 * @ingroup Orthanc
8712 **/
8713 ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginCallRestApi(
8714 OrthancPluginContext* context,
8715 OrthancPluginMemoryBuffer* answerBody,
8716 OrthancPluginMemoryBuffer* answerHeaders,
8717 uint16_t* httpStatus,
8718 OrthancPluginHttpMethod method,
8719 const char* uri,
8720 uint32_t headersCount,
8721 const char* const* headersKeys,
8722 const char* const* headersValues,
8723 const void* body,
8724 uint32_t bodySize,
8725 uint8_t afterPlugins)
8726 {
8727 _OrthancPluginCallRestApi params;
8728 memset(&params, 0, sizeof(params));
8729
8730 params.answerBody = answerBody;
8731 params.answerHeaders = answerHeaders;
8732 params.httpStatus = httpStatus;
8733 params.method = method;
8734 params.uri = uri;
8735 params.headersCount = headersCount;
8736 params.headersKeys = headersKeys;
8737 params.headersValues = headersValues;
8738 params.body = body;
8739 params.bodySize = bodySize;
8740 params.afterPlugins = afterPlugins;
8741
8742 return context->InvokeService(context, _OrthancPluginService_CallRestApi, &params);
8743 }
8744
8745
8746 #ifdef __cplusplus
8747 }
8748 #endif
8749
8750
8751 /** @} */
8752