Mercurial > hg > orthanc
comparison Plugins/Samples/WebSkeleton/Framework/Plugin.cpp @ 1628:77c4cc4def0f
OrthancPluginErrorCode in REST callbacks
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Sep 2015 16:46:35 +0200 |
parents | 97268448bdfc |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1627:da7854deb662 | 1628:77c4cc4def0f |
---|---|
129 return ok; | 129 return ok; |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 #if ORTHANC_PLUGIN_STANDALONE == 1 | 133 #if ORTHANC_PLUGIN_STANDALONE == 1 |
134 static int32_t ServeStaticResource(OrthancPluginRestOutput* output, | 134 static OrthancPluginErrorCode ServeStaticResource(OrthancPluginRestOutput* output, |
135 const char* url, | 135 const char* url, |
136 const OrthancPluginHttpRequest* request) | 136 const OrthancPluginHttpRequest* request) |
137 { | 137 { |
138 if (request->method != OrthancPluginHttpMethod_Get) | 138 if (request->method != OrthancPluginHttpMethod_Get) |
139 { | 139 { |
140 OrthancPluginSendMethodNotAllowed(context, output, "GET"); | 140 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
141 return 0; | 141 return OrthancPluginErrorCode_Success; |
142 } | 142 } |
143 | 143 |
144 std::string path = "/" + std::string(request->groups[0]); | 144 std::string path = "/" + std::string(request->groups[0]); |
145 const char* mime = GetMimeType(path); | 145 const char* mime = GetMimeType(path); |
146 | 146 |
150 Orthanc::EmbeddedResources::GetDirectoryResource | 150 Orthanc::EmbeddedResources::GetDirectoryResource |
151 (s, Orthanc::EmbeddedResources::STATIC_RESOURCES, path.c_str()); | 151 (s, Orthanc::EmbeddedResources::STATIC_RESOURCES, path.c_str()); |
152 | 152 |
153 const char* resource = s.size() ? s.c_str() : NULL; | 153 const char* resource = s.size() ? s.c_str() : NULL; |
154 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); | 154 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); |
155 | |
156 return 0; | |
157 } | 155 } |
158 catch (std::runtime_error&) | 156 catch (std::runtime_error&) |
159 { | 157 { |
160 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); | 158 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); |
161 OrthancPluginLogError(context, s.c_str()); | 159 OrthancPluginLogError(context, s.c_str()); |
162 OrthancPluginSendHttpStatusCode(context, output, 404); | 160 OrthancPluginSendHttpStatusCode(context, output, 404); |
163 return 0; | 161 } |
164 } | 162 |
163 return OrthancPluginErrorCode_Success; | |
165 } | 164 } |
166 #endif | 165 #endif |
167 | 166 |
168 | 167 |
169 #if ORTHANC_PLUGIN_STANDALONE == 0 | 168 #if ORTHANC_PLUGIN_STANDALONE == 0 |
170 static int32_t ServeFolder(OrthancPluginRestOutput* output, | 169 static OrthancPluginErrorCode ServeFolder(OrthancPluginRestOutput* output, |
171 const char* url, | 170 const char* url, |
172 const OrthancPluginHttpRequest* request) | 171 const OrthancPluginHttpRequest* request) |
173 { | 172 { |
174 if (request->method != OrthancPluginHttpMethod_Get) | 173 if (request->method != OrthancPluginHttpMethod_Get) |
175 { | 174 { |
176 OrthancPluginSendMethodNotAllowed(context, output, "GET"); | 175 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
177 return 0; | 176 return OrthancPluginErrorCode_Success; |
178 } | 177 } |
179 | 178 |
180 std::string path = ORTHANC_PLUGIN_RESOURCES_ROOT "/" + std::string(request->groups[0]); | 179 std::string path = ORTHANC_PLUGIN_RESOURCES_ROOT "/" + std::string(request->groups[0]); |
181 const char* mime = GetMimeType(path); | 180 const char* mime = GetMimeType(path); |
182 | 181 |
183 std::string s; | 182 std::string s; |
184 if (ReadFile(s, path)) | 183 if (ReadFile(s, path)) |
185 { | 184 { |
186 const char* resource = s.size() ? s.c_str() : NULL; | 185 const char* resource = s.size() ? s.c_str() : NULL; |
187 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); | 186 OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); |
188 | |
189 return 0; | |
190 } | 187 } |
191 else | 188 else |
192 { | 189 { |
193 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); | 190 std::string s = "Unknown static resource in plugin: " + std::string(request->groups[0]); |
194 OrthancPluginLogError(context, s.c_str()); | 191 OrthancPluginLogError(context, s.c_str()); |
195 OrthancPluginSendHttpStatusCode(context, output, 404); | 192 OrthancPluginSendHttpStatusCode(context, output, 404); |
196 return 0; | 193 } |
197 } | 194 |
198 } | 195 return OrthancPluginErrorCode_Success; |
199 #endif | 196 } |
200 | 197 #endif |
201 | 198 |
202 static int32_t RedirectRoot(OrthancPluginRestOutput* output, | 199 |
203 const char* url, | 200 static OrthancPluginErrorCode RedirectRoot(OrthancPluginRestOutput* output, |
204 const OrthancPluginHttpRequest* request) | 201 const char* url, |
202 const OrthancPluginHttpRequest* request) | |
205 { | 203 { |
206 if (request->method != OrthancPluginHttpMethod_Get) | 204 if (request->method != OrthancPluginHttpMethod_Get) |
207 { | 205 { |
208 OrthancPluginSendMethodNotAllowed(context, output, "GET"); | 206 OrthancPluginSendMethodNotAllowed(context, output, "GET"); |
209 } | 207 } |
210 else | 208 else |
211 { | 209 { |
212 OrthancPluginRedirect(context, output, ORTHANC_PLUGIN_WEB_ROOT "index.html"); | 210 OrthancPluginRedirect(context, output, ORTHANC_PLUGIN_WEB_ROOT "index.html"); |
213 } | 211 } |
214 | 212 |
215 return 0; | 213 return OrthancPluginErrorCode_Success; |
216 } | 214 } |
217 | 215 |
218 | 216 |
219 extern "C" | 217 extern "C" |
220 { | 218 { |