comparison Resources/Orthanc/Sdk-1.12.4/orthanc/OrthancCPlugin.h @ 511:51a78b3f96bb OrthancMySQL-5.2

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