Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/ConnectivityChecks/Plugin.cpp @ 5545:f8b9eaa5effa
re-enabling ICU in the multitenant dicom plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 22 Mar 2024 22:07:06 +0100 |
parents | 6ce05f8b5b13 |
children | f7adfb22e20e |
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 |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5257
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5257
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3622
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * 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
|
9 * 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
|
10 * 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
|
11 * License, or (at your option) any later version. |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * 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
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * General Public License for more details. |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * 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
|
19 * 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
|
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 |
5257
0b183bb77c83
Avoid the use of "externalproject_add()" to build the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
23 #include <ConnectivityChecksResources.h> |
3622
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <orthanc/OrthancCPlugin.h> |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
4045 | 26 #include "../../../../OrthancFramework/Sources/OrthancException.h" |
27 #include "../../../../OrthancFramework/Sources/SystemToolbox.h" | |
3622
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 #define ROOT_URI "/connectivity-checks" |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 static OrthancPluginContext* context_ = NULL; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 template <Orthanc::EmbeddedResources::DirectoryResourceId DIRECTORY> |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 static OrthancPluginErrorCode ServeStaticResource(OrthancPluginRestOutput* output, |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 const char* url, |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 const OrthancPluginHttpRequest* request) |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 if (request->method != OrthancPluginHttpMethod_Get) |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 return OrthancPluginErrorCode_Success; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 std::string path = "/" + std::string(request->groups[0]); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 std::string mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(path)); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 try |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 std::string s; |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 Orthanc::EmbeddedResources::GetDirectoryResource(s, DIRECTORY, path.c_str()); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 const char* resource = s.size() ? s.c_str() : NULL; |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime.c_str()); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 catch (Orthanc::OrthancException&) |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 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
|
60 OrthancPluginLogError(context_, s.c_str()); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 OrthancPluginSendHttpStatusCode(context_, output, 404); |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 return OrthancPluginErrorCode_Success; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 extern "C" |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 context_ = c; |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 /* Check the version of the Orthanc core */ |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 if (OrthancPluginCheckVersion(c) == 0) |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 char info[256]; |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 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
|
80 c->orthancVersion, |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 OrthancPluginLogError(context_, info); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 return -1; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 /* Register the callbacks */ |
5538
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
89 OrthancPluginSetDescription2(context_, ORTHANC_PLUGIN_NAME, "Utilities to check connectivity to DICOM modalities, DICOMweb servers and Orthanc peers."); |
6ce05f8b5b13
deprecating OrthancPluginSetDescription2(), OrthancPluginExtendOrthancExplorer2() and OrthancPluginSetRootUri2()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
90 OrthancPluginSetRootUri2(context_, ORTHANC_PLUGIN_NAME, ROOT_URI "/app/index.html"); |
3622
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/libs/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::LIBRARIES>); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 OrthancPluginRegisterRestCallback(context_, ROOT_URI "/app/(.*)", ServeStaticResource<Orthanc::EmbeddedResources::WEB_RESOURCES>); |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 return 0; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 return ORTHANC_PLUGIN_NAME; |
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 |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 { |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 return ORTHANC_PLUGIN_VERSION; |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 } |
8afc14fab01f
New sample plugin: ConnectivityChecks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 } |