comparison RenderingPlugin/Resources/Orthanc/Plugins/OrthancPluginCppWrapper.cpp @ 1913:6a65b7cb77ab

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 20 Mar 2022 17:54:31 +0100
parents a2955abe4c2e
children 224d7763eede
comparison
equal deleted inserted replaced
1912:7947565ed2b7 1913:6a65b7cb77ab
509 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); 509 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
510 } 510 }
511 } 511 }
512 512
513 513
514 void OrthancString::ToJsonWithoutComments(Json::Value& target) const
515 {
516 if (str_ == NULL)
517 {
518 LogError("Cannot convert an empty memory buffer to JSON");
519 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
520 }
521
522 if (!ReadJsonWithoutComments(target, str_))
523 {
524 LogError("Cannot convert some memory buffer to JSON");
525 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
526 }
527 }
528
529
514 void MemoryBuffer::DicomToJson(Json::Value& target, 530 void MemoryBuffer::DicomToJson(Json::Value& target,
515 OrthancPluginDicomToJsonFormat format, 531 OrthancPluginDicomToJsonFormat format,
516 OrthancPluginDicomToJsonFlags flags, 532 OrthancPluginDicomToJsonFlags flags,
517 uint32_t maxStringLength) 533 uint32_t maxStringLength)
518 { 534 {
643 { 659 {
644 LogError("Cannot access the Orthanc configuration"); 660 LogError("Cannot access the Orthanc configuration");
645 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 661 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
646 } 662 }
647 663
648 str.ToJson(configuration_); 664 str.ToJsonWithoutComments(configuration_);
649 665
650 if (configuration_.type() != Json::objectValue) 666 if (configuration_.type() != Json::objectValue)
651 { 667 {
652 LogError("Unable to read the Orthanc configuration"); 668 LogError("Unable to read the Orthanc configuration");
653 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); 669 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError);
2508 { 2524 {
2509 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); 2525 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
2510 } 2526 }
2511 catch (...) 2527 catch (...)
2512 { 2528 {
2513 return OrthancPluginErrorCode_InternalError; 2529 return OrthancPluginErrorCode_Plugin;
2514 } 2530 }
2515 } 2531 }
2516 } 2532 }
2517 }; 2533 };
2518 2534
3530 result->toFree_ = true; 3546 result->toFree_ = true;
3531 return result.release(); 3547 return result.release();
3532 } 3548 }
3533 } 3549 }
3534 #endif 3550 #endif
3551
3552
3553 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3554 static std::vector<std::string> WebDavConvertPath(uint32_t pathSize,
3555 const char* const* pathItems)
3556 {
3557 std::vector<std::string> result(pathSize);
3558
3559 for (uint32_t i = 0; i < pathSize; i++)
3560 {
3561 result[i] = pathItems[i];
3562 }
3563
3564 return result;
3565 }
3566 #endif
3567
3568
3569 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3570 static OrthancPluginErrorCode WebDavIsExistingFolder(uint8_t* isExisting,
3571 uint32_t pathSize,
3572 const char* const* pathItems,
3573 void* payload)
3574 {
3575 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3576
3577 try
3578 {
3579 *isExisting = (that.IsExistingFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
3580 return OrthancPluginErrorCode_Success;
3581 }
3582 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3583 {
3584 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3585 }
3586 catch (...)
3587 {
3588 return OrthancPluginErrorCode_Plugin;
3589 }
3590 }
3591 #endif
3592
3593
3594 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3595 static OrthancPluginErrorCode WebDavListFolder(uint8_t* isExisting,
3596 OrthancPluginWebDavCollection* collection,
3597 OrthancPluginWebDavAddFile addFile,
3598 OrthancPluginWebDavAddFolder addFolder,
3599 uint32_t pathSize,
3600 const char* const* pathItems,
3601 void* payload)
3602 {
3603 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3604
3605 try
3606 {
3607 std::list<IWebDavCollection::FileInfo> files;
3608 std::list<IWebDavCollection::FolderInfo> subfolders;
3609
3610 if (!that.ListFolder(files, subfolders, WebDavConvertPath(pathSize, pathItems)))
3611 {
3612 *isExisting = 0;
3613 }
3614 else
3615 {
3616 *isExisting = 1;
3617
3618 for (std::list<IWebDavCollection::FileInfo>::const_iterator
3619 it = files.begin(); it != files.end(); ++it)
3620 {
3621 OrthancPluginErrorCode code = addFile(
3622 collection, it->GetName().c_str(), it->GetContentSize(),
3623 it->GetMimeType().c_str(), it->GetDateTime().c_str());
3624
3625 if (code != OrthancPluginErrorCode_Success)
3626 {
3627 return code;
3628 }
3629 }
3630
3631 for (std::list<IWebDavCollection::FolderInfo>::const_iterator it =
3632 subfolders.begin(); it != subfolders.end(); ++it)
3633 {
3634 OrthancPluginErrorCode code = addFolder(
3635 collection, it->GetName().c_str(), it->GetDateTime().c_str());
3636
3637 if (code != OrthancPluginErrorCode_Success)
3638 {
3639 return code;
3640 }
3641 }
3642 }
3643
3644 return OrthancPluginErrorCode_Success;
3645 }
3646 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3647 {
3648 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3649 }
3650 catch (...)
3651 {
3652 return OrthancPluginErrorCode_Plugin;
3653 }
3654 }
3655 #endif
3656
3657
3658 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3659 static OrthancPluginErrorCode WebDavRetrieveFile(OrthancPluginWebDavCollection* collection,
3660 OrthancPluginWebDavRetrieveFile retrieveFile,
3661 uint32_t pathSize,
3662 const char* const* pathItems,
3663 void* payload)
3664 {
3665 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3666
3667 try
3668 {
3669 std::string content, mime, dateTime;
3670
3671 if (that.GetFile(content, mime, dateTime, WebDavConvertPath(pathSize, pathItems)))
3672 {
3673 return retrieveFile(collection, content.empty() ? NULL : content.c_str(),
3674 content.size(), mime.c_str(), dateTime.c_str());
3675 }
3676 else
3677 {
3678 // Inexisting file
3679 return OrthancPluginErrorCode_Success;
3680 }
3681 }
3682 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3683 {
3684 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3685 }
3686 catch (...)
3687 {
3688 return OrthancPluginErrorCode_InternalError;
3689 }
3690 }
3691 #endif
3692
3693
3694 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3695 static OrthancPluginErrorCode WebDavStoreFileCallback(uint8_t* isReadOnly, /* out */
3696 uint32_t pathSize,
3697 const char* const* pathItems,
3698 const void* data,
3699 uint64_t size,
3700 void* payload)
3701 {
3702 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3703
3704 try
3705 {
3706 *isReadOnly = (that.StoreFile(WebDavConvertPath(pathSize, pathItems), data, size) ? 1 : 0);
3707 return OrthancPluginErrorCode_Success;
3708 }
3709 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3710 {
3711 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3712 }
3713 catch (...)
3714 {
3715 return OrthancPluginErrorCode_InternalError;
3716 }
3717 }
3718 #endif
3719
3720
3721 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3722 static OrthancPluginErrorCode WebDavCreateFolderCallback(uint8_t* isReadOnly, /* out */
3723 uint32_t pathSize,
3724 const char* const* pathItems,
3725 void* payload)
3726 {
3727 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3728
3729 try
3730 {
3731 *isReadOnly = (that.CreateFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
3732 return OrthancPluginErrorCode_Success;
3733 }
3734 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3735 {
3736 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3737 }
3738 catch (...)
3739 {
3740 return OrthancPluginErrorCode_InternalError;
3741 }
3742 }
3743 #endif
3744
3745
3746 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3747 static OrthancPluginErrorCode WebDavDeleteItemCallback(uint8_t* isReadOnly, /* out */
3748 uint32_t pathSize,
3749 const char* const* pathItems,
3750 void* payload)
3751 {
3752 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload);
3753
3754 try
3755 {
3756 *isReadOnly = (that.DeleteItem(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0);
3757 return OrthancPluginErrorCode_Success;
3758 }
3759 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e)
3760 {
3761 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
3762 }
3763 catch (...)
3764 {
3765 return OrthancPluginErrorCode_InternalError;
3766 }
3767 }
3768 #endif
3769
3770
3771 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1
3772 void IWebDavCollection::Register(const std::string& uri,
3773 IWebDavCollection& collection)
3774 {
3775 OrthancPluginErrorCode code = OrthancPluginRegisterWebDavCollection(
3776 GetGlobalContext(), uri.c_str(), WebDavIsExistingFolder, WebDavListFolder, WebDavRetrieveFile,
3777 WebDavStoreFileCallback, WebDavCreateFolderCallback, WebDavDeleteItemCallback, &collection);
3778
3779 if (code != OrthancPluginErrorCode_Success)
3780 {
3781 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code);
3782 }
3783 }
3784 #endif
3535 } 3785 }