comparison Plugins/Samples/ServeFolders/Plugin.cpp @ 2177:11420238f337

ORTHANC_PLUGINS_THROW_EXCEPTION macro
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Nov 2016 12:29:28 +0100
parents fead5549aaa7
children 395522e46b2b
comparison
equal deleted inserted replaced
2176:fead5549aaa7 2177:11420238f337
200 { 200 {
201 content.ReadFile(path); 201 content.ReadFile(path);
202 } 202 }
203 catch (...) 203 catch (...)
204 { 204 {
205 OrthancPlugins::ThrowException(OrthancPluginErrorCode_InexistentFile); 205 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InexistentFile);
206 } 206 }
207 207
208 boost::posix_time::ptime lastModification = boost::posix_time::from_time_t(fs::last_write_time(path)); 208 boost::posix_time::ptime lastModification = boost::posix_time::from_time_t(fs::last_write_time(path));
209 std::string t = boost::posix_time::to_iso_string(lastModification); 209 std::string t = boost::posix_time::to_iso_string(lastModification);
210 OrthancPluginSetHttpHeader(context_, output, "Last-Modified", t.c_str()); 210 OrthancPluginSetHttpHeader(context_, output, "Last-Modified", t.c_str());
253 static void ConfigureFolders(const Json::Value& folders) 253 static void ConfigureFolders(const Json::Value& folders)
254 { 254 {
255 if (folders.type() != Json::objectValue) 255 if (folders.type() != Json::objectValue)
256 { 256 {
257 OrthancPlugins::LogError(context_, "The list of folders to be served is badly formatted (must be a JSON object)"); 257 OrthancPlugins::LogError(context_, "The list of folders to be served is badly formatted (must be a JSON object)");
258 OrthancPlugins::ThrowException(OrthancPluginErrorCode_BadFileFormat); 258 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
259 } 259 }
260 260
261 Json::Value::Members members = folders.getMemberNames(); 261 Json::Value::Members members = folders.getMemberNames();
262 262
263 // Register the callback for each base URI 263 // Register the callback for each base URI
266 { 266 {
267 if (folders[*it].type() != Json::stringValue) 267 if (folders[*it].type() != Json::stringValue)
268 { 268 {
269 OrthancPlugins::LogError(context_, "The folder to be served \"" + *it + 269 OrthancPlugins::LogError(context_, "The folder to be served \"" + *it +
270 "\" must be associated with a string value (its mapped URI)"); 270 "\" must be associated with a string value (its mapped URI)");
271 OrthancPlugins::ThrowException(OrthancPluginErrorCode_BadFileFormat); 271 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
272 } 272 }
273 273
274 std::string baseUri = *it; 274 std::string baseUri = *it;
275 275
276 // Remove the heading and trailing slashes in the root URI, if any 276 // Remove the heading and trailing slashes in the root URI, if any
287 } 287 }
288 288
289 if (baseUri.empty()) 289 if (baseUri.empty())
290 { 290 {
291 OrthancPlugins::LogError(context_, "The URI of a folder to be served cannot be empty"); 291 OrthancPlugins::LogError(context_, "The URI of a folder to be served cannot be empty");
292 OrthancPlugins::ThrowException(OrthancPluginErrorCode_BadFileFormat); 292 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
293 } 293 }
294 294
295 // Check whether the source folder exists and is indeed a directory 295 // Check whether the source folder exists and is indeed a directory
296 const std::string folder = folders[*it].asString(); 296 const std::string folder = folders[*it].asString();
297 if (!boost::filesystem::is_directory(folder)) 297 if (!boost::filesystem::is_directory(folder))
298 { 298 {
299 OrthancPlugins::LogError(context_, "Trying and serve an inexistent folder: " + folder); 299 OrthancPlugins::LogError(context_, "Trying and serve an inexistent folder: " + folder);
300 OrthancPlugins::ThrowException(OrthancPluginErrorCode_InexistentFile); 300 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_InexistentFile);
301 } 301 }
302 302
303 folders_[baseUri] = folder; 303 folders_[baseUri] = folder;
304 304
305 // Register the callback to serve the folder 305 // Register the callback to serve the folder
314 static void ConfigureExtensions(const Json::Value& extensions) 314 static void ConfigureExtensions(const Json::Value& extensions)
315 { 315 {
316 if (extensions.type() != Json::objectValue) 316 if (extensions.type() != Json::objectValue)
317 { 317 {
318 OrthancPlugins::LogError(context_, "The list of extensions is badly formatted (must be a JSON object)"); 318 OrthancPlugins::LogError(context_, "The list of extensions is badly formatted (must be a JSON object)");
319 OrthancPlugins::ThrowException(OrthancPluginErrorCode_BadFileFormat); 319 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
320 } 320 }
321 321
322 Json::Value::Members members = extensions.getMemberNames(); 322 Json::Value::Members members = extensions.getMemberNames();
323 323
324 for (Json::Value::Members::const_iterator 324 for (Json::Value::Members::const_iterator
326 { 326 {
327 if (extensions[*it].type() != Json::stringValue) 327 if (extensions[*it].type() != Json::stringValue)
328 { 328 {
329 OrthancPlugins::LogError(context_, "The file extension \"" + *it + 329 OrthancPlugins::LogError(context_, "The file extension \"" + *it +
330 "\" must be associated with a string value (its MIME type)"); 330 "\" must be associated with a string value (its MIME type)");
331 OrthancPlugins::ThrowException(OrthancPluginErrorCode_BadFileFormat); 331 ORTHANC_PLUGINS_THROW_EXCEPTION(OrthancPluginErrorCode_BadFileFormat);
332 } 332 }
333 333
334 const std::string& mime = extensions[*it].asString(); 334 const std::string& mime = extensions[*it].asString();
335 335
336 std::string name = *it; 336 std::string name = *it;