annotate OrthancServer/Plugins/Samples/ConnectivityChecks/Plugin.cpp @ 4454:f20a7655fb1c

Fix upload of multiple DICOM files using one single POST call to "multipart/form-data"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 Jan 2021 12:03:49 +0100
parents d9473bd5ed43
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4122
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * General Public License for more details.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include <EmbeddedResources.h>
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include <orthanc/OrthancCPlugin.h>
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
25 #include "../../../../OrthancFramework/Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
26 #include "../../../../OrthancFramework/Sources/SystemToolbox.h"
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #define ROOT_URI "/connectivity-checks"
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static OrthancPluginContext* context_ = NULL;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 template <Orthanc::EmbeddedResources::DirectoryResourceId DIRECTORY>
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static OrthancPluginErrorCode ServeStaticResource(OrthancPluginRestOutput* output,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 const char* url,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 const OrthancPluginHttpRequest* request)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 if (request->method != OrthancPluginHttpMethod_Get)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 return OrthancPluginErrorCode_Success;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 std::string path = "/" + std::string(request->groups[0]);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 std::string mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(path));
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 try
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 std::string s;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 Orthanc::EmbeddedResources::GetDirectoryResource(s, DIRECTORY, path.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 const char* resource = s.size() ? s.c_str() : NULL;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 catch (Orthanc::OrthancException&)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 OrthancPluginLogError(context_, s.c_str());
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 OrthancPluginSendHttpStatusCode(context_, output, 404);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 return OrthancPluginErrorCode_Success;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 extern "C"
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 context_ = c;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 /* Check the version of the Orthanc core */
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if (OrthancPluginCheckVersion(c) == 0)
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 char info[256];
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 c->orthancVersion,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 OrthancPluginLogError(context_, info);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 return -1;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 /* Register the callbacks */
3628
70398cc7aa15 yet another try...
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3622
diff changeset
88 OrthancPluginSetDescription(context_, "Utilities to check connectivity to DICOM modalities, DICOMweb servers and Orthanc peers.");
3622
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 OrthancPluginSetRootUri(context_, ROOT_URI "/app/index.html");
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/libs/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::LIBRARIES>);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/app/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::WEB_RESOURCES>);
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 return 0;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 return ORTHANC_PLUGIN_NAME;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 return ORTHANC_PLUGIN_VERSION;
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 }
8afc14fab01f New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }