Mercurial > hg > orthanc
annotate Plugins/Samples/ServeFolders/Plugin.cpp @ 2062:40ffd0e8676a
generation of etag in ServeFolders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 02 Jul 2016 15:09:03 +0200 |
parents | 8856f15b3e02 |
children | 700dbb3baac9 |
rev | line source |
---|---|
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
9 * License, or (at your option) any later version. |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
10 * |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, but |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
14 * General Public License for more details. |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * |
1375
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
3d76e26b3865
fix licensing terms of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1323
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 **/ |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
21 #include "../Common/OrthancPluginCppWrapper.h" |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
23 #include <json/reader.h> |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
24 #include <json/value.h> |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
25 #include <boost/filesystem.hpp> |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
26 #include <boost/date_time/posix_time/posix_time.hpp> |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
27 |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 static OrthancPluginContext* context_ = NULL; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
30 static std::map<std::string, std::string> folders_; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
31 static const char* INDEX_URI = "/app/plugin-serve-folders.html"; |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
32 static bool allowCache_ = true; |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
33 static bool generateETag_ = true; // TODO parameter |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
34 |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
35 |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
36 static void SetHttpHeaders(OrthancPluginRestOutput* output) |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
37 { |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
38 if (!allowCache_) |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
39 { |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
40 // http://stackoverflow.com/a/2068407/881731 |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
41 OrthancPluginSetHttpHeader(context_, output, "Cache-Control", "no-cache, no-store, must-revalidate"); |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
42 OrthancPluginSetHttpHeader(context_, output, "Pragma", "no-cache"); |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
43 OrthancPluginSetHttpHeader(context_, output, "Expires", "0"); |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
44 } |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
45 } |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
46 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
47 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
48 static const char* GetMimeType(const std::string& path) |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
49 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
50 size_t dot = path.find_last_of('.'); |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
51 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
52 std::string extension = (dot == std::string::npos) ? "" : path.substr(dot); |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
53 std::transform(extension.begin(), extension.end(), extension.begin(), tolower); |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
54 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
55 if (extension == ".html") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
56 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
57 return "text/html"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
58 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
59 else if (extension == ".css") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
60 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
61 return "text/css"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
62 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
63 else if (extension == ".js") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
64 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
65 return "application/javascript"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
66 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
67 else if (extension == ".gif") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
68 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
69 return "image/gif"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
70 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
71 else if (extension == ".svg") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
72 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
73 return "image/svg+xml"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
74 } |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
75 else if (extension == ".json" || |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
76 extension == ".nmf") |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
77 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
78 return "application/json"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
79 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
80 else if (extension == ".xml") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
81 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
82 return "application/xml"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
83 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
84 else if (extension == ".png") |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
85 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
86 return "image/png"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
87 } |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
88 else if (extension == ".jpg" || |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
89 extension == ".jpeg") |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
90 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
91 return "image/jpeg"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
92 } |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
93 else if (extension == ".woff") |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
94 { |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
95 return "application/x-font-woff"; |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
96 } |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
97 else if (extension == ".pexe") |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
98 { |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
99 return "application/x-pnacl"; |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
100 } |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
101 else if (extension == ".nexe") |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
102 { |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
103 return "application/x-nacl"; |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
104 } |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
105 else |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
106 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
107 std::string s = "Unknown MIME type for extension: " + extension; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
108 OrthancPluginLogWarning(context_, s.c_str()); |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
109 return "application/octet-stream"; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
110 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
111 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
112 |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
114 static bool ReadFile(std::string& target, |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
115 const std::string& path) |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
116 { |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
117 try |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
118 { |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
119 OrthancPlugins::MemoryBuffer buffer(context_); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
120 buffer.ReadFile(path); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
121 buffer.ToString(target); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
122 return true; |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
123 } |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
124 catch (OrthancPlugins::PluginException) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
125 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
126 return false; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
127 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
128 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
129 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
130 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
131 static bool ReadConfiguration(Json::Value& configuration, |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
132 OrthancPluginContext* context) |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 { |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
134 std::string s; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
135 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
136 { |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
137 char* tmp = OrthancPluginGetConfiguration(context); |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
138 if (tmp == NULL) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
139 { |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
140 OrthancPluginLogError(context, "Error while retrieving the configuration from Orthanc"); |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
141 return false; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
142 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
143 |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
144 s.assign(tmp); |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
145 OrthancPluginFreeString(context, tmp); |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
146 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
147 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
148 Json::Reader reader; |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
149 if (reader.parse(s, configuration)) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
150 { |
1425
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
151 return true; |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
152 } |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
153 else |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
154 { |
97268448bdfc
refactoring of samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1391
diff
changeset
|
155 OrthancPluginLogError(context, "Unable to parse the configuration"); |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
156 return false; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
157 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
158 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
159 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
160 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
161 |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
162 static bool LookupFolder(std::string& folder, |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
163 OrthancPluginRestOutput* output, |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
164 const OrthancPluginHttpRequest* request) |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
165 { |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
166 const std::string uri = request->groups[0]; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
167 |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
168 std::map<std::string, std::string>::const_iterator found = folders_.find(uri); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
169 if (found == folders_.end()) |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
170 { |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
171 std::string s = "Unknown URI in plugin server-folders: " + uri; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
172 OrthancPluginLogError(context_, s.c_str()); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
173 OrthancPluginSendHttpStatusCode(context_, output, 404); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
174 return false; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
175 } |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
176 else |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
177 { |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
178 folder = found->second; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
179 return true; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
180 } |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
181 } |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
182 |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
183 |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
184 static OrthancPluginErrorCode FolderCallback(OrthancPluginRestOutput* output, |
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
185 const char* url, |
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
186 const OrthancPluginHttpRequest* request) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
187 { |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
188 namespace fs = boost::filesystem; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
189 |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
190 if (request->method != OrthancPluginHttpMethod_Get) |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
191 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
192 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
193 return OrthancPluginErrorCode_Success; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
194 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
195 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
196 std::string folder; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
197 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
198 if (LookupFolder(folder, output, request)) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
199 { |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
200 const fs::path item(request->groups[1]); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
201 const fs::path parent((fs::path(folder) / item).parent_path()); |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
202 |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
203 if (item.filename().string() == "index.html" && |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
204 fs::is_directory(parent) && |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
205 !fs::is_regular_file(fs::path(folder) / item)) |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
206 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
207 // On-the-fly generation of an "index.html" |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
208 std::string s; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
209 s += "<html>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
210 s += " <body>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
211 s += " <ul>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
212 |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
213 fs::directory_iterator end; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
214 |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
215 for (fs::directory_iterator it(parent) ; it != end; ++it) |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
216 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
217 if (fs::is_directory(it->status())) |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
218 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
219 std::string f = it->path().filename().string(); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
220 s += " <li><a href=\"" + f + "/index.html\">" + f + "/</a></li>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
221 } |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
222 } |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
223 |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
224 for (fs::directory_iterator it(parent) ; it != end; ++it) |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
225 { |
1911 | 226 fs::file_type type = it->status().type(); |
227 | |
228 if (type == fs::regular_file || | |
229 type == fs::reparse_file) // cf. BitBucket issue #11 | |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
230 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
231 std::string f = it->path().filename().string(); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
232 s += " <li><a href=\"" + f + "\">" + f + "</a></li>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
233 } |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
234 } |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
235 |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
236 s += " </ul>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
237 s += " </body>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
238 s += "</html>\n"; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
239 |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
240 SetHttpHeaders(output); |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
241 OrthancPluginAnswerBuffer(context_, output, s.c_str(), s.size(), "text/html"); |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
242 } |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
243 else |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
244 { |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
245 std::string path = folder + "/" + item.string(); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
246 const char* mime = GetMimeType(path); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
247 |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
248 std::string s; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
249 if (ReadFile(s, path)) |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
250 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
251 const char* resource = s.size() ? s.c_str() : NULL; |
2062
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
252 |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
253 if (generateETag_) |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
254 { |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
255 OrthancPlugins::OrthancString md5(context_, OrthancPluginComputeMd5(context_, resource, s.size())); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
256 std::string etag = "\"" + std::string(md5.GetContent()) + "\""; |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
257 OrthancPluginSetHttpHeader(context_, output, "ETag", etag.c_str()); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
258 } |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
259 |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
260 boost::posix_time::ptime lastModification = boost::posix_time::from_time_t(fs::last_write_time(path)); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
261 std::string t = boost::posix_time::to_iso_string(lastModification); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
262 OrthancPluginSetHttpHeader(context_, output, "Last-Modified", t.c_str()); |
40ffd0e8676a
generation of etag in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2061
diff
changeset
|
263 |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
264 SetHttpHeaders(output); |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
265 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
266 } |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
267 else |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
268 { |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
269 std::string s = "Inexistent file in served folder: " + path; |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
270 OrthancPluginLogError(context_, s.c_str()); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
271 OrthancPluginSendHttpStatusCode(context_, output, 404); |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
272 } |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
273 } |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
274 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
275 |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
276 return OrthancPluginErrorCode_Success; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
277 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
278 |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
279 |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
280 static OrthancPluginErrorCode ListServedFolders(OrthancPluginRestOutput* output, |
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
281 const char* url, |
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
282 const OrthancPluginHttpRequest* request) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
283 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
284 if (request->method != OrthancPluginHttpMethod_Get) |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
285 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
286 OrthancPluginSendMethodNotAllowed(context_, output, "GET"); |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
287 return OrthancPluginErrorCode_Success; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
288 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
289 |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
290 std::string s = "<html><body><h1>Additional folders served by Orthanc</h1>\n"; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
291 |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
292 if (folders_.empty()) |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
293 { |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
294 s += "<p>Empty section <tt>ServeFolders</tt> in your configuration file: No additional folder is served.</p>\n"; |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
295 } |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
296 else |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
297 { |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
298 s += "<ul>\n"; |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
299 for (std::map<std::string, std::string>::const_iterator |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
300 it = folders_.begin(); it != folders_.end(); ++it) |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
301 { |
1597
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
302 // The URI is relative to INDEX_URI ("/app/plugin-serve-folders.html") |
415dfd1d1c61
Improvements to the sample "ServeFolders" plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1589
diff
changeset
|
303 s += "<li><a href=\"../" + it->first + "/index.html\">" + it->first + "</li>\n"; |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
304 } |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
305 |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
306 s += "</ul>\n"; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
307 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
308 |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
309 s += "</body></html>\n"; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
310 |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
311 SetHttpHeaders(output); |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
312 OrthancPluginAnswerBuffer(context_, output, s.c_str(), s.size(), "text/html"); |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
313 |
1628
77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1597
diff
changeset
|
314 return OrthancPluginErrorCode_Success; |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 extern "C" |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 { |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 { |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 context_ = context; |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 /* Check the version of the Orthanc core */ |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 if (OrthancPluginCheckVersion(context_) == 0) |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 { |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 char info[1024]; |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 context_->orthancVersion, |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
333 OrthancPluginLogError(context_, info); |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 return -1; |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 OrthancPluginSetDescription(context_, "Serve additional folders with the HTTP server of Orthanc."); |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
339 Json::Value configuration; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
340 if (!ReadConfiguration(configuration, context_)) |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
341 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
342 return -1; |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
343 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
344 |
2061
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
345 if (configuration.isMember("ServeFoldersNoCache")) |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
346 { |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
347 OrthancPluginLogWarning(context_, "Disabling the cache"); |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
348 allowCache_ = false; |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
349 } |
8856f15b3e02
disabling cache in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1911
diff
changeset
|
350 |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
351 if (configuration.isMember("ServeFolders")) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
352 { |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
353 if (configuration["ServeFolders"].type() != Json::objectValue) |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
354 { |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
355 OrthancPluginLogError(context_, "The \"ServeFolders\" configuration section is badly formatted (must be a JSON object)"); |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
356 return -1; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
357 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
358 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
359 else |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
360 { |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
361 OrthancPluginLogWarning(context_, "No section \"ServeFolders\" in your configuration file: " |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
362 "No additional folder will be served!"); |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
363 configuration["ServeFolders"] = Json::objectValue; |
1323
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
364 } |
5a92665dee23
Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1322
diff
changeset
|
365 |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
366 |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
367 Json::Value::Members members = configuration["ServeFolders"].getMemberNames(); |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
368 |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
369 // Register the callback for each base URI |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
370 for (Json::Value::Members::const_iterator |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
371 it = members.begin(); it != members.end(); ++it) |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
372 { |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
373 std::string baseUri = *it; |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
374 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
375 // Remove the heading and trailing slashes in the root URI, if any |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
376 while (!baseUri.empty() && |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
377 *baseUri.begin() == '/') |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
378 { |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
379 baseUri = baseUri.substr(1); |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
380 } |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
381 |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
382 while (!baseUri.empty() && |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
383 *baseUri.rbegin() == '/') |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
384 { |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
385 baseUri.resize(baseUri.size() - 1); |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
386 } |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
387 |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
388 if (baseUri.empty()) |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
389 { |
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
390 OrthancPluginLogError(context_, "The URI of a folder to be served cannot be empty"); |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
391 return -1; |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
392 } |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
393 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
394 // Check whether the source folder exists and is indeed a directory |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
395 const std::string folder = configuration["ServeFolders"][*it].asString(); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
396 if (!boost::filesystem::is_directory(folder)) |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
397 { |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
398 std::string msg = "Trying and serve an inexistent folder: " + folder; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
399 OrthancPluginLogError(context_, msg.c_str()); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
400 return -1; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
401 } |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
402 |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
403 folders_[baseUri] = folder; |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
404 |
1589
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
405 // Register the callback to serve the folder |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
406 { |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
407 const std::string regex = "/(" + baseUri + ")/(.*)"; |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
408 OrthancPluginRegisterRestCallback(context, regex.c_str(), FolderCallback); |
334d3a92ed83
improvements to the ServeFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1588
diff
changeset
|
409 } |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
410 } |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
411 |
1588
b5bc87a7212d
OrthancPluginReadFile, OrthancPluginWriteFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1434
diff
changeset
|
412 OrthancPluginRegisterRestCallback(context, INDEX_URI, ListServedFolders); |
1434
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
413 OrthancPluginSetRootUri(context, INDEX_URI); |
f9cd40166269
refactoring of OrthancPlugins, improvement in ServeFolders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1425
diff
changeset
|
414 |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 return 0; |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 { |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
423 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 { |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 return "serve-folders"; |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 { |
1391
b3119c32c920
version in ServerFolders plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1384
diff
changeset
|
432 return SERVE_FOLDERS_VERSION; |
1322
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
433 } |
f497a72d9f71
fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 } |