Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 3433:caa526bb65cc
fixed C++ compatibility wrapper for OrthancPluginRegisterRestCallbackNoLock()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Jun 2019 09:10:27 +0200 |
parents | 00737cd21f40 |
children | 6503ab9489ba |
comparison
equal
deleted
inserted
replaced
3432:297ad330900c | 3433:caa526bb65cc |
---|---|
2752 } | 2752 } |
2753 } | 2753 } |
2754 | 2754 |
2755 #else | 2755 #else |
2756 | 2756 |
2757 void ChunkedRestCompatibility(OrthancPluginRestOutput* output, | 2757 OrthancPluginErrorCode ChunkedRestCompatibility(OrthancPluginRestOutput* output, |
2758 const char* url, | 2758 const char* url, |
2759 const OrthancPluginHttpRequest* request, | 2759 const OrthancPluginHttpRequest* request, |
2760 RestCallback GetHandler, | 2760 RestCallback GetHandler, |
2761 ChunkedRestCallback PostHandler, | 2761 ChunkedRestCallback PostHandler, |
2762 RestCallback DeleteHandler, | 2762 RestCallback DeleteHandler, |
2763 ChunkedRestCallback PutHandler) | 2763 ChunkedRestCallback PutHandler) |
2764 { | 2764 { |
2765 std::string allowed; | 2765 try |
2766 | 2766 { |
2767 if (GetHandler != Internals::NullRestCallback) | 2767 std::string allowed; |
2768 { | 2768 |
2769 allowed += "GET"; | 2769 if (GetHandler != Internals::NullRestCallback) |
2770 } | |
2771 | |
2772 if (PostHandler != Internals::NullChunkedRestCallback) | |
2773 { | |
2774 if (!allowed.empty()) | |
2775 { | 2770 { |
2776 allowed += ","; | 2771 allowed += "GET"; |
2777 } | 2772 } |
2773 | |
2774 if (PostHandler != Internals::NullChunkedRestCallback) | |
2775 { | |
2776 if (!allowed.empty()) | |
2777 { | |
2778 allowed += ","; | |
2779 } | |
2778 | 2780 |
2779 allowed += "POST"; | 2781 allowed += "POST"; |
2780 } | 2782 } |
2781 | 2783 |
2782 if (DeleteHandler != Internals::NullRestCallback) | 2784 if (DeleteHandler != Internals::NullRestCallback) |
2783 { | |
2784 if (!allowed.empty()) | |
2785 { | 2785 { |
2786 allowed += ","; | 2786 if (!allowed.empty()) |
2787 { | |
2788 allowed += ","; | |
2789 } | |
2790 | |
2791 allowed += "DELETE"; | |
2787 } | 2792 } |
2793 | |
2794 if (PutHandler != Internals::NullChunkedRestCallback) | |
2795 { | |
2796 if (!allowed.empty()) | |
2797 { | |
2798 allowed += ","; | |
2799 } | |
2788 | 2800 |
2789 allowed += "DELETE"; | 2801 allowed += "PUT"; |
2790 } | 2802 } |
2791 | 2803 |
2792 if (PutHandler != Internals::NullChunkedRestCallback) | 2804 switch (request->method) |
2793 { | |
2794 if (!allowed.empty()) | |
2795 { | 2805 { |
2796 allowed += ","; | 2806 case OrthancPluginHttpMethod_Get: |
2797 } | 2807 if (GetHandler == Internals::NullRestCallback) |
2798 | |
2799 allowed += "PUT"; | |
2800 } | |
2801 | |
2802 switch (request->method) | |
2803 { | |
2804 case OrthancPluginHttpMethod_Get: | |
2805 { | |
2806 if (GetHandler == Internals::NullRestCallback) | |
2807 { | |
2808 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2809 } | |
2810 else | |
2811 { | |
2812 GetHandler(output, url, request); | |
2813 } | |
2814 return; | |
2815 } | |
2816 | |
2817 case OrthancPluginHttpMethod_Post: | |
2818 { | |
2819 if (PostHandler == Internals::NullChunkedRestCallback) | |
2820 { | |
2821 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2822 } | |
2823 else | |
2824 { | |
2825 std::auto_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); | |
2826 if (reader.get() == NULL) | |
2827 { | 2808 { |
2828 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | 2809 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
2829 } | 2810 } |
2830 else | 2811 else |
2831 { | 2812 { |
2832 reader->AddChunk(request->body, request->bodySize); | 2813 GetHandler(output, url, request); |
2833 reader->Execute(output); | |
2834 } | 2814 } |
2835 } | 2815 |
2836 return; | 2816 break; |
2837 } | 2817 |
2838 | 2818 case OrthancPluginHttpMethod_Post: |
2839 case OrthancPluginHttpMethod_Delete: | 2819 if (PostHandler == Internals::NullChunkedRestCallback) |
2840 { | |
2841 if (DeleteHandler == Internals::NullRestCallback) | |
2842 { | |
2843 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2844 } | |
2845 else | |
2846 { | |
2847 DeleteHandler(output, url, request); | |
2848 } | |
2849 return; | |
2850 } | |
2851 | |
2852 case OrthancPluginHttpMethod_Put: | |
2853 { | |
2854 if (PutHandler == Internals::NullChunkedRestCallback) | |
2855 { | |
2856 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2857 } | |
2858 else | |
2859 { | |
2860 std::auto_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); | |
2861 if (reader.get() == NULL) | |
2862 { | 2820 { |
2863 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | 2821 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); |
2864 } | 2822 } |
2865 else | 2823 else |
2866 { | 2824 { |
2867 reader->AddChunk(request->body, request->bodySize); | 2825 std::auto_ptr<IChunkedRequestReader> reader(PostHandler(url, request)); |
2868 reader->Execute(output); | 2826 if (reader.get() == NULL) |
2827 { | |
2828 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
2829 } | |
2830 else | |
2831 { | |
2832 reader->AddChunk(request->body, request->bodySize); | |
2833 reader->Execute(output); | |
2834 } | |
2869 } | 2835 } |
2870 } | 2836 |
2871 return; | 2837 break; |
2838 | |
2839 case OrthancPluginHttpMethod_Delete: | |
2840 if (DeleteHandler == Internals::NullRestCallback) | |
2841 { | |
2842 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2843 } | |
2844 else | |
2845 { | |
2846 DeleteHandler(output, url, request); | |
2847 } | |
2848 | |
2849 break; | |
2850 | |
2851 case OrthancPluginHttpMethod_Put: | |
2852 if (PutHandler == Internals::NullChunkedRestCallback) | |
2853 { | |
2854 OrthancPluginSendMethodNotAllowed(GetGlobalContext(), output, allowed.c_str()); | |
2855 } | |
2856 else | |
2857 { | |
2858 std::auto_ptr<IChunkedRequestReader> reader(PutHandler(url, request)); | |
2859 if (reader.get() == NULL) | |
2860 { | |
2861 ORTHANC_PLUGINS_THROW_EXCEPTION(Plugin); | |
2862 } | |
2863 else | |
2864 { | |
2865 reader->AddChunk(request->body, request->bodySize); | |
2866 reader->Execute(output); | |
2867 } | |
2868 } | |
2869 | |
2870 break; | |
2871 | |
2872 default: | |
2873 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | |
2872 } | 2874 } |
2873 | 2875 |
2874 default: | 2876 return OrthancPluginErrorCode_Success; |
2875 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | 2877 } |
2876 } | 2878 catch (ORTHANC_PLUGINS_EXCEPTION_CLASS& e) |
2877 } | 2879 { |
2880 #if HAS_ORTHANC_EXCEPTION == 1 && HAS_ORTHANC_PLUGIN_EXCEPTION_DETAILS == 1 | |
2881 if (HasGlobalContext() && | |
2882 e.HasDetails()) | |
2883 { | |
2884 // The "false" instructs Orthanc not to log the detailed | |
2885 // error message. This is to avoid duplicating the details, | |
2886 // because "OrthancException" already does it on construction. | |
2887 OrthancPluginSetHttpErrorDetails | |
2888 (GetGlobalContext(), output, e.GetDetails(), false); | |
2889 } | |
2878 #endif | 2890 #endif |
2891 | |
2892 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); | |
2893 } | |
2894 catch (boost::bad_lexical_cast&) | |
2895 { | |
2896 return OrthancPluginErrorCode_BadFileFormat; | |
2897 } | |
2898 catch (...) | |
2899 { | |
2900 return OrthancPluginErrorCode_Plugin; | |
2901 } | |
2902 } | |
2903 #endif | |
2879 } | 2904 } |
2880 } | 2905 } |