annotate Plugins/Samples/ServeFolders/Plugin.cpp @ 1371:f528849ee9f7 query-retrieve

DICOM Query/Retrieve available from Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 27 May 2015 17:33:13 +0200
parents 5a92665dee23
children 3d76e26b3865
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 *
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * Permission is hereby granted, free of charge, to any person
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * obtaining a copy of this software and associated documentation
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * files (the "Software"), to deal in the Software without
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * restriction, including without limitation the rights to use, copy,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * of the Software, and to permit persons to whom the Software is
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * included in all copies or substantial portions of the Software.
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * SOFTWARE.
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 **/
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <OrthancCPlugin.h>
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
30 #include <json/reader.h>
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
31 #include <json/value.h>
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <string.h>
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <stdio.h>
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
34 #include <fstream>
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
35 #include <algorithm>
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
36 #include <sys/stat.h>
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 static OrthancPluginContext* context_ = NULL;
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
39 static std::map<std::string, std::string> folders_;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
40 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
41
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 static const char* GetMimeType(const std::string& path)
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 size_t dot = path.find_last_of('.');
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 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
48 std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
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 if (extension == ".html")
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 return "text/html";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
53 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
54 else if (extension == ".css")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
55 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
56 return "text/css";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
57 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
58 else if (extension == ".js")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
59 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
60 return "application/javascript";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
61 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
62 else if (extension == ".gif")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
63 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
64 return "image/gif";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
65 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
66 else if (extension == ".svg")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
67 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
68 return "image/svg+xml";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
69 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
70 else if (extension == ".json")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
71 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
72 return "application/json";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
73 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
74 else if (extension == ".xml")
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
75 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
76 return "application/xml";
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 else if (extension == ".png")
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 return "image/png";
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 else if (extension == ".jpg" || extension == ".jpeg")
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 return "image/jpeg";
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 else
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
87 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
88 std::string s = "Unknown MIME type for extension: " + extension;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
89 OrthancPluginLogWarning(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
90 return "application/octet-stream";
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 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
93
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
96 static bool ReadFile(std::string& content,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
97 const std::string& path)
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 struct stat s;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
100 if (stat(path.c_str(), &s) != 0 ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
101 !(s.st_mode & S_IFREG))
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 // 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
104 return false;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
107 FILE* fp = fopen(path.c_str(), "rb");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
108 if (fp == NULL)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
109 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
110 return false;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
113 long size;
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 if (fseek(fp, 0, SEEK_END) == -1 ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
116 (size = ftell(fp)) < 0)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
117 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
118 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
119 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
120 }
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 content.resize(size);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
123
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
124 if (fseek(fp, 0, SEEK_SET) == -1)
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 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
127 return false;
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 bool ok = true;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
131
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
132 if (size > 0 &&
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
133 fread(&content[0], size, 1, fp) != 1)
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 ok = false;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
138 fclose(fp);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
139
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
140 return ok;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
144 static bool ReadConfiguration(Json::Value& configuration,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
145 OrthancPluginContext* context)
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
147 std::string path;
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 char* pathTmp = OrthancPluginGetConfigurationPath(context);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
151 if (pathTmp == NULL)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
152 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
153 OrthancPluginLogError(context, "No configuration file is provided");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
154 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
155 }
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 path = std::string(pathTmp);
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 OrthancPluginFreeString(context, pathTmp);
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
162 std::ifstream f(path.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
163
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
164 Json::Reader reader;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
165 if (!reader.parse(f, configuration) ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
166 configuration.type() != Json::objectValue)
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 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
169 OrthancPluginLogError(context, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
170 return false;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
171 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
172
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
173 return true;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
174 }
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
177 static int32_t FolderCallback(OrthancPluginRestOutput* output,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
178 const char* url,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
179 const OrthancPluginHttpRequest* request)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
180 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
181 if (request->method != OrthancPluginHttpMethod_Get)
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 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
184 return 0;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
187 const std::string uri = request->groups[0];
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
188 const std::string item = request->groups[1];
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
189
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
190 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
191 if (found == folders_.end())
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
192 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
193 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
194 OrthancPluginLogError(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
195 OrthancPluginSendHttpStatusCode(context_, output, 404);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
196 return 0;
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
199 std::string path = found->second + "/" + item;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
200 const char* mime = GetMimeType(path);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
201
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
202 std::string s;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
203 if (ReadFile(s, path))
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
204 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
205 const char* resource = s.size() ? s.c_str() : NULL;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
206 OrthancPluginAnswerBuffer(context_, output, resource, s.size(), mime);
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 else
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 std::string s = "Inexistent file in served folder: " + path;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
211 OrthancPluginLogError(context_, s.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
212 OrthancPluginSendHttpStatusCode(context_, output, 404);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
213 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
214
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
215 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
216 }
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
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
219 static int32_t IndexCallback(OrthancPluginRestOutput* output,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
220 const char* url,
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
221 const OrthancPluginHttpRequest* request)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
222 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
223 if (request->method != OrthancPluginHttpMethod_Get)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
224 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
225 OrthancPluginSendMethodNotAllowed(context_, output, "GET");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
226 return 0;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
227 }
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 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
230
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
231 for (std::map<std::string, std::string>::const_iterator
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
232 it = folders_.begin(); it != folders_.end(); it++)
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 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
235 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
236
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
237 s += "</ul></body></html>";
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
238
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
239 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
240
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
241 return 0;
1322
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
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
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 extern "C"
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 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 context_ = context;
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 /* Check the version of the Orthanc core */
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 if (OrthancPluginCheckVersion(context_) == 0)
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 char info[1024];
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 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
257 context_->orthancVersion,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
261 OrthancPluginLogError(context_, info);
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 return -1;
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 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
266
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
267 Json::Value configuration;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
268 if (!ReadConfiguration(configuration, context_))
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
269 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
270 return -1;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
271 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
272
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
273 if (configuration.isMember("ServeFolders") &&
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
274 configuration["ServeFolders"].type() == Json::objectValue)
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
275 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
276 Json::Value::Members members = configuration["ServeFolders"].getMemberNames();
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 // Register the callback for each base URI
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
279 for (Json::Value::Members::const_iterator
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
280 it = members.begin(); it != members.end(); it++)
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 const std::string& baseUri = *it;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
283 const std::string path = configuration["ServeFolders"][*it].asString();
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
284 const std::string regex = "(" + baseUri + ")/(.*)";
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 if (baseUri.empty() ||
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
287 *baseUri.rbegin() == '/')
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 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
290 OrthancPluginLogWarning(context_, message.c_str());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
291 return -1;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
292 }
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 OrthancPluginRegisterRestCallback(context, regex.c_str(), FolderCallback);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
295 folders_[baseUri] = path;
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
296 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
297
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
298 OrthancPluginRegisterRestCallback(context, INDEX_URI, IndexCallback);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
299 OrthancPluginSetRootUri(context, INDEX_URI);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
300 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
301 else
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
302 {
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
303 OrthancPluginLogWarning(context_, "No section \"ServeFolders\" in your configuration file: "
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
304 "No additional folder will be served!");
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
305 }
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1322
diff changeset
306
1322
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 return 0;
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
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 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
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
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
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 return "serve-folders";
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
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 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
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 return "1.0";
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
f497a72d9f71 fixes to the sample plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }