comparison OrthancServer/Sources/ServerContext.cpp @ 4860:3e9a76464e8a openssl-3.x

integration mainline->openssl-3.x
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Dec 2021 16:52:51 +0100
parents 2e71a08eea15 8b51d65584f0
children 6eff25f70121
comparison
equal deleted inserted replaced
4832:2e71a08eea15 4860:3e9a76464e8a
33 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h" 33 #include "../../OrthancFramework/Sources/FileStorage/StorageAccessor.h"
34 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h" 34 #include "../../OrthancFramework/Sources/HttpServer/FilesystemHttpSender.h"
35 #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h" 35 #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h"
36 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" 36 #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h"
37 #include "../../OrthancFramework/Sources/Logging.h" 37 #include "../../OrthancFramework/Sources/Logging.h"
38 #include "../../OrthancFramework/Sources/MallocMemoryBuffer.h"
38 #include "../../OrthancFramework/Sources/MetricsRegistry.h" 39 #include "../../OrthancFramework/Sources/MetricsRegistry.h"
39 #include "../Plugins/Engine/OrthancPlugins.h" 40 #include "../Plugins/Engine/OrthancPlugins.h"
40 41
41 #include "OrthancConfiguration.h" 42 #include "OrthancConfiguration.h"
42 #include "OrthancRestApi/OrthancRestApi.h" 43 #include "OrthancRestApi/OrthancRestApi.h"
680 } 681 }
681 } 682 }
682 683
683 684
684 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId, 685 ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId,
685 DicomInstanceToStore& dicom, 686 DicomInstanceToStore& receivedDicom,
686 StoreInstanceMode mode) 687 StoreInstanceMode mode)
687 { 688 {
689 DicomInstanceToStore* dicom = &receivedDicom;
690 std::unique_ptr<DicomInstanceToStore> modifiedDicom;
691
692 std::unique_ptr<MallocMemoryBuffer> raii(new MallocMemoryBuffer);
693
694 #if ORTHANC_ENABLE_PLUGINS == 1
695 if (HasPlugins())
696 {
697 void* modifiedDicomBuffer = NULL;
698 size_t modifiedDicomBufferSize = 0;
699
700 bool store = GetPlugins().ApplyReceivedInstanceCallbacks(receivedDicom.GetBufferData(),
701 receivedDicom.GetBufferSize(),
702 &modifiedDicomBuffer,
703 modifiedDicomBufferSize);
704 raii->Assign(modifiedDicomBuffer, modifiedDicomBufferSize, ::free);
705
706 if (!store)
707 {
708 StoreResult result;
709 result.SetStatus(StoreStatus_FilteredOut);
710 return result;
711 }
712
713 if (modifiedDicomBufferSize > 0 && modifiedDicomBuffer != NULL)
714 {
715 modifiedDicom.reset(DicomInstanceToStore::CreateFromBuffer(modifiedDicomBuffer, modifiedDicomBufferSize));
716 modifiedDicom->SetOrigin(dicom->GetOrigin());
717 dicom = modifiedDicom.get();
718 }
719 }
720 #endif
721
688 if (!isIngestTranscoding_) 722 if (!isIngestTranscoding_)
689 { 723 {
690 // No automated transcoding. This was the only path in Orthanc <= 1.6.1. 724 // No automated transcoding. This was the only path in Orthanc <= 1.6.1.
691 return StoreAfterTranscoding(resultPublicId, dicom, mode); 725 return StoreAfterTranscoding(resultPublicId, *dicom, mode);
692 } 726 }
693 else 727 else
694 { 728 {
695 // Automated transcoding of incoming DICOM instance 729 // Automated transcoding of incoming DICOM instance
696 730
697 bool transcode = false; 731 bool transcode = false;
698 732
699 DicomTransferSyntax sourceSyntax; 733 DicomTransferSyntax sourceSyntax;
700 if (!dicom.LookupTransferSyntax(sourceSyntax) || 734 if (!dicom->LookupTransferSyntax(sourceSyntax) ||
701 sourceSyntax == ingestTransferSyntax_) 735 sourceSyntax == ingestTransferSyntax_)
702 { 736 {
703 // Don't transcode if the incoming DICOM is already in the proper transfer syntax 737 // Don't transcode if the incoming DICOM is already in the proper transfer syntax
704 transcode = false; 738 transcode = false;
705 } 739 }
722 } 756 }
723 757
724 if (!transcode) 758 if (!transcode)
725 { 759 {
726 // No transcoding 760 // No transcoding
727 return StoreAfterTranscoding(resultPublicId, dicom, mode); 761 return StoreAfterTranscoding(resultPublicId, *dicom, mode);
728 } 762 }
729 else 763 else
730 { 764 {
731 // Trancoding 765 // Trancoding
732 std::set<DicomTransferSyntax> syntaxes; 766 std::set<DicomTransferSyntax> syntaxes;
733 syntaxes.insert(ingestTransferSyntax_); 767 syntaxes.insert(ingestTransferSyntax_);
734 768
735 IDicomTranscoder::DicomImage source; 769 IDicomTranscoder::DicomImage source;
736 source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize()); 770 source.SetExternalBuffer(dicom->GetBufferData(), dicom->GetBufferSize());
737 771
738 IDicomTranscoder::DicomImage transcoded; 772 IDicomTranscoder::DicomImage transcoded;
739 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) 773 if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */))
740 { 774 {
741 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); 775 std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
742 776
743 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*tmp)); 777 std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*tmp));
744 toStore->SetOrigin(dicom.GetOrigin()); 778 toStore->SetOrigin(dicom->GetOrigin());
745 779
746 StoreResult result = StoreAfterTranscoding(resultPublicId, *toStore, mode); 780 StoreResult result = StoreAfterTranscoding(resultPublicId, *toStore, mode);
747 assert(resultPublicId == tmp->GetHasher().HashInstance()); 781 assert(resultPublicId == tmp->GetHasher().HashInstance());
748 782
749 return result; 783 return result;
750 } 784 }
751 else 785 else
752 { 786 {
753 // Cannot transcode => store the original file 787 // Cannot transcode => store the original file
754 return StoreAfterTranscoding(resultPublicId, dicom, mode); 788 return StoreAfterTranscoding(resultPublicId, *dicom, mode);
755 } 789 }
756 } 790 }
757 } 791 }
758 } 792 }
759 793