Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 4962:501411a67f10 more-tags
merge
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 23 Mar 2022 12:23:11 +0100 |
parents | 1b76853e1797 47d734fa30f6 |
children | 03632ed1eb67 |
comparison
equal
deleted
inserted
replaced
4961:1b76853e1797 | 4962:501411a67f10 |
---|---|
2532 { | 2532 { |
2533 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | 2533 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); |
2534 } | 2534 } |
2535 catch (...) | 2535 catch (...) |
2536 { | 2536 { |
2537 return OrthancPluginErrorCode_InternalError; | 2537 return OrthancPluginErrorCode_Plugin; |
2538 } | 2538 } |
2539 } | 2539 } |
2540 } | 2540 } |
2541 }; | 2541 }; |
2542 | 2542 |
3554 result->toFree_ = true; | 3554 result->toFree_ = true; |
3555 return result.release(); | 3555 return result.release(); |
3556 } | 3556 } |
3557 } | 3557 } |
3558 #endif | 3558 #endif |
3559 | |
3560 | |
3561 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3562 static std::vector<std::string> WebDavConvertPath(uint32_t pathSize, | |
3563 const char* const* pathItems) | |
3564 { | |
3565 std::vector<std::string> result(pathSize); | |
3566 | |
3567 for (uint32_t i = 0; i < pathSize; i++) | |
3568 { | |
3569 result[i] = pathItems[i]; | |
3570 } | |
3571 | |
3572 return result; | |
3573 } | |
3574 #endif | |
3575 | |
3576 | |
3577 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3578 static OrthancPluginErrorCode WebDavIsExistingFolder(uint8_t* isExisting, | |
3579 uint32_t pathSize, | |
3580 const char* const* pathItems, | |
3581 void* payload) | |
3582 { | |
3583 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3584 | |
3585 try | |
3586 { | |
3587 *isExisting = (that.IsExistingFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); | |
3588 return OrthancPluginErrorCode_Success; | |
3589 } | |
3590 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3591 { | |
3592 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3593 } | |
3594 catch (...) | |
3595 { | |
3596 return OrthancPluginErrorCode_Plugin; | |
3597 } | |
3598 } | |
3599 #endif | |
3600 | |
3601 | |
3602 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3603 static OrthancPluginErrorCode WebDavListFolder(uint8_t* isExisting, | |
3604 OrthancPluginWebDavCollection* collection, | |
3605 OrthancPluginWebDavAddFile addFile, | |
3606 OrthancPluginWebDavAddFolder addFolder, | |
3607 uint32_t pathSize, | |
3608 const char* const* pathItems, | |
3609 void* payload) | |
3610 { | |
3611 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3612 | |
3613 try | |
3614 { | |
3615 std::list<IWebDavCollection::FileInfo> files; | |
3616 std::list<IWebDavCollection::FolderInfo> subfolders; | |
3617 | |
3618 if (!that.ListFolder(files, subfolders, WebDavConvertPath(pathSize, pathItems))) | |
3619 { | |
3620 *isExisting = 0; | |
3621 } | |
3622 else | |
3623 { | |
3624 *isExisting = 1; | |
3625 | |
3626 for (std::list<IWebDavCollection::FileInfo>::const_iterator | |
3627 it = files.begin(); it != files.end(); ++it) | |
3628 { | |
3629 OrthancPluginErrorCode code = addFile( | |
3630 collection, it->GetName().c_str(), it->GetContentSize(), | |
3631 it->GetMimeType().c_str(), it->GetDateTime().c_str()); | |
3632 | |
3633 if (code != OrthancPluginErrorCode_Success) | |
3634 { | |
3635 return code; | |
3636 } | |
3637 } | |
3638 | |
3639 for (std::list<IWebDavCollection::FolderInfo>::const_iterator it = | |
3640 subfolders.begin(); it != subfolders.end(); ++it) | |
3641 { | |
3642 OrthancPluginErrorCode code = addFolder( | |
3643 collection, it->GetName().c_str(), it->GetDateTime().c_str()); | |
3644 | |
3645 if (code != OrthancPluginErrorCode_Success) | |
3646 { | |
3647 return code; | |
3648 } | |
3649 } | |
3650 } | |
3651 | |
3652 return OrthancPluginErrorCode_Success; | |
3653 } | |
3654 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3655 { | |
3656 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3657 } | |
3658 catch (...) | |
3659 { | |
3660 return OrthancPluginErrorCode_Plugin; | |
3661 } | |
3662 } | |
3663 #endif | |
3664 | |
3665 | |
3666 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3667 static OrthancPluginErrorCode WebDavRetrieveFile(OrthancPluginWebDavCollection* collection, | |
3668 OrthancPluginWebDavRetrieveFile retrieveFile, | |
3669 uint32_t pathSize, | |
3670 const char* const* pathItems, | |
3671 void* payload) | |
3672 { | |
3673 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3674 | |
3675 try | |
3676 { | |
3677 std::string content, mime, dateTime; | |
3678 | |
3679 if (that.GetFile(content, mime, dateTime, WebDavConvertPath(pathSize, pathItems))) | |
3680 { | |
3681 return retrieveFile(collection, content.empty() ? NULL : content.c_str(), | |
3682 content.size(), mime.c_str(), dateTime.c_str()); | |
3683 } | |
3684 else | |
3685 { | |
3686 // Inexisting file | |
3687 return OrthancPluginErrorCode_Success; | |
3688 } | |
3689 } | |
3690 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3691 { | |
3692 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3693 } | |
3694 catch (...) | |
3695 { | |
3696 return OrthancPluginErrorCode_InternalError; | |
3697 } | |
3698 } | |
3699 #endif | |
3700 | |
3701 | |
3702 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3703 static OrthancPluginErrorCode WebDavStoreFileCallback(uint8_t* isReadOnly, /* out */ | |
3704 uint32_t pathSize, | |
3705 const char* const* pathItems, | |
3706 const void* data, | |
3707 uint64_t size, | |
3708 void* payload) | |
3709 { | |
3710 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3711 | |
3712 try | |
3713 { | |
3714 *isReadOnly = (that.StoreFile(WebDavConvertPath(pathSize, pathItems), data, size) ? 1 : 0); | |
3715 return OrthancPluginErrorCode_Success; | |
3716 } | |
3717 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3718 { | |
3719 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3720 } | |
3721 catch (...) | |
3722 { | |
3723 return OrthancPluginErrorCode_InternalError; | |
3724 } | |
3725 } | |
3726 #endif | |
3727 | |
3728 | |
3729 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3730 static OrthancPluginErrorCode WebDavCreateFolderCallback(uint8_t* isReadOnly, /* out */ | |
3731 uint32_t pathSize, | |
3732 const char* const* pathItems, | |
3733 void* payload) | |
3734 { | |
3735 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3736 | |
3737 try | |
3738 { | |
3739 *isReadOnly = (that.CreateFolder(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); | |
3740 return OrthancPluginErrorCode_Success; | |
3741 } | |
3742 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3743 { | |
3744 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3745 } | |
3746 catch (...) | |
3747 { | |
3748 return OrthancPluginErrorCode_InternalError; | |
3749 } | |
3750 } | |
3751 #endif | |
3752 | |
3753 | |
3754 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3755 static OrthancPluginErrorCode WebDavDeleteItemCallback(uint8_t* isReadOnly, /* out */ | |
3756 uint32_t pathSize, | |
3757 const char* const* pathItems, | |
3758 void* payload) | |
3759 { | |
3760 IWebDavCollection& that = *reinterpret_cast<IWebDavCollection*>(payload); | |
3761 | |
3762 try | |
3763 { | |
3764 *isReadOnly = (that.DeleteItem(WebDavConvertPath(pathSize, pathItems)) ? 1 : 0); | |
3765 return OrthancPluginErrorCode_Success; | |
3766 } | |
3767 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) | |
3768 { | |
3769 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
3770 } | |
3771 catch (...) | |
3772 { | |
3773 return OrthancPluginErrorCode_InternalError; | |
3774 } | |
3775 } | |
3776 #endif | |
3777 | |
3778 | |
3779 #if HAS_ORTHANC_PLUGIN_WEBDAV == 1 | |
3780 void IWebDavCollection::Register(const std::string& uri, | |
3781 IWebDavCollection& collection) | |
3782 { | |
3783 OrthancPluginErrorCode code = OrthancPluginRegisterWebDavCollection( | |
3784 GetGlobalContext(), uri.c_str(), WebDavIsExistingFolder, WebDavListFolder, WebDavRetrieveFile, | |
3785 WebDavStoreFileCallback, WebDavCreateFolderCallback, WebDavDeleteItemCallback, &collection); | |
3786 | |
3787 if (code != OrthancPluginErrorCode_Success) | |
3788 { | |
3789 ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(code); | |
3790 } | |
3791 } | |
3792 #endif | |
3559 } | 3793 } |