annotate Plugins/Samples/ServeFolders/Plugin.cpp @ 1384:d6971e18a324

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 29 May 2015 15:00:24 +0200
parents 3d76e26b3865
children b3119c32c920
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #include <OrthancCPlugin.h>
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>
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <string.h>
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <stdio.h>
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
27 #include <fstream>
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
28 #include <algorithm>
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
29 #include <sys/stat.h>
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static OrthancPluginContext* context_ = NULL;
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
32 static std::map<std::string, std::string> folders_;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
33 static const char* INDEX_URI = "/app/plugin-serve-folders.html";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
34
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
35
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
36 static const char* GetMimeType(const std::string& path)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
37 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
38 size_t dot = path.find_last_of('.');
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
39
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
40 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
41 std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
42
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
43 if (extension == ".html")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
44 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
45 return "text/html";
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 else if (extension == ".css")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
48 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
49 return "text/css";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
50 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
51 else if (extension == ".js")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
52 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
53 return "application/javascript";
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 else if (extension == ".gif")
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 "image/gif";
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 == ".svg")
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 "image/svg+xml";
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 == ".json")
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/json";
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 == ".xml")
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 "application/xml";
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 == ".png")
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/png";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
74 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
75 else if (extension == ".jpg" || extension == ".jpeg")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
76 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
77 return "image/jpeg";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
78 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
79 else
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
80 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
81 std::string s = "Unknown MIME type for extension: " + extension;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
82 OrthancPluginLogWarning(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
83 return "application/octet-stream";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
84 }
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
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
89 static bool ReadFile(std::string& content,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
90 const std::string& path)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
91 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
92 struct stat s;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
93 if (stat(path.c_str(), &s) != 0 ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
94 !(s.st_mode & S_IFREG))
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
95 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
96 // Either the path does not exist, or it is not a regular file
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
97 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
98 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
99
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
100 FILE* fp = fopen(path.c_str(), "rb");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
101 if (fp == NULL)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
102 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
103 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
104 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
105
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
106 long size;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
107
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
108 if (fseek(fp, 0, SEEK_END) == -1 ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
109 (size = ftell(fp)) < 0)
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 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
112 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
113 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
114
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
115 content.resize(size);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
116
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
117 if (fseek(fp, 0, SEEK_SET) == -1)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
118 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
119 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
120 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
121 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
122
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
123 bool ok = true;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
124
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
125 if (size > 0 &&
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
126 fread(&content[0], size, 1, fp) != 1)
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 ok = false;
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 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
132
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
133 return ok;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
134 }
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
137 static bool ReadConfiguration(Json::Value& configuration,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
138 OrthancPluginContext* context)
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
140 std::string path;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
141
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 char* pathTmp = OrthancPluginGetConfigurationPath(context);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
144 if (pathTmp == NULL)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
145 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
146 OrthancPluginLogError(context, "No configuration file is provided");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
147 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
148 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
149
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
150 path = std::string(pathTmp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
151
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
152 OrthancPluginFreeString(context, pathTmp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
153 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
154
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
155 std::ifstream f(path.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
156
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
157 Json::Reader reader;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
158 if (!reader.parse(f, configuration) ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
159 configuration.type() != Json::objectValue)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
160 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
161 std::string s = "Unable to parse the configuration file: " + std::string(path);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
162 OrthancPluginLogError(context, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
163 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
164 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
165
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
166 return true;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
167 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
168
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
169
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
170 static int32_t FolderCallback(OrthancPluginRestOutput* output,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
171 const char* url,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
172 const OrthancPluginHttpRequest* request)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
173 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
174 if (request->method != OrthancPluginHttpMethod_Get)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
175 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
176 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
177 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
178 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
179
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
180 const std::string uri = request->groups[0];
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
181 const std::string item = request->groups[1];
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
182
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
183 std::map<std::string, std::string>::const_iterator found = folders_.find(uri);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
184 if (found == folders_.end())
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
185 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
186 std::string s = "Unknown URI in plugin server-folders: " + uri;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
187 OrthancPluginLogError(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
188 OrthancPluginSendHttpStatusCode(context_, output, 404);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
189 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
190 }
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 std::string path = found->second + "/" + item;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
193 const char* mime = GetMimeType(path);
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 std::string s;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
196 if (ReadFile(s, path))
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
197 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
198 const char* resource = s.size() ? s.c_str() : NULL;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
199 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
200 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
201 else
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
202 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
203 std::string s = "Inexistent file in served folder: " + path;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
204 OrthancPluginLogError(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
205 OrthancPluginSendHttpStatusCode(context_, output, 404);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
206 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
207
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
208 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
209 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
210
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
211
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
212 static int32_t IndexCallback(OrthancPluginRestOutput* output,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
213 const char* url,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
214 const OrthancPluginHttpRequest* request)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
215 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
216 if (request->method != OrthancPluginHttpMethod_Get)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
217 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
218 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
219 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
220 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
221
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
222 std::string s = "<html><body><h1>Additional folders served by Orthanc</h1><ul>\n";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
223
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
224 for (std::map<std::string, std::string>::const_iterator
1384
d6971e18a324 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1375
diff changeset
225 it = folders_.begin(); it != folders_.end(); ++it)
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
226 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
227 s += "<li><a href=\"" + it->first + "/index.html\">" + it->first + "</li>\n";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
228 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
229
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
230 s += "</ul></body></html>";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
231
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
232 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
233
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
234 return 0;
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 extern "C"
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 context_ = context;
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 /* Check the version of the Orthanc core */
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (OrthancPluginCheckVersion(context_) == 0)
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 char info[1024];
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 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
250 context_->orthancVersion,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
254 OrthancPluginLogError(context_, info);
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 return -1;
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 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
259
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
260 Json::Value configuration;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
261 if (!ReadConfiguration(configuration, context_))
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
262 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
263 return -1;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
264 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
265
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
266 if (configuration.isMember("ServeFolders") &&
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
267 configuration["ServeFolders"].type() == Json::objectValue)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
268 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
269 Json::Value::Members members = configuration["ServeFolders"].getMemberNames();
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
270
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
271 // Register the callback for each base URI
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
272 for (Json::Value::Members::const_iterator
1384
d6971e18a324 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1375
diff changeset
273 it = members.begin(); it != members.end(); ++it)
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 const std::string& baseUri = *it;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
276 const std::string path = configuration["ServeFolders"][*it].asString();
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
277 const std::string regex = "(" + baseUri + ")/(.*)";
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 if (baseUri.empty() ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
280 *baseUri.rbegin() == '/')
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
281 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
282 std::string message = "The URI of a folder to be server cannot be empty or end with a '/': " + *it;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
283 OrthancPluginLogWarning(context_, message.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
284 return -1;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
287 OrthancPluginRegisterRestCallback(context, regex.c_str(), FolderCallback);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
288 folders_[baseUri] = path;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
289 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
290
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
291 OrthancPluginRegisterRestCallback(context, INDEX_URI, IndexCallback);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
292 OrthancPluginSetRootUri(context, INDEX_URI);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
293 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
294 else
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
295 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
296 OrthancPluginLogWarning(context_, "No section \"ServeFolders\" in your configuration file: "
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
297 "No additional folder will be served!");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
298 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
299
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 return 0;
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 return "serve-folders";
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
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 return "1.0";
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }