Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp Thu Nov 25 19:02:38 2021 +0100 +++ b/OrthancServer/Sources/ServerContext.cpp Fri Dec 24 16:52:51 2021 +0100 @@ -35,6 +35,7 @@ #include "../../OrthancFramework/Sources/HttpServer/HttpStreamTranscoder.h" #include "../../OrthancFramework/Sources/JobsEngine/SetOfInstancesJob.h" #include "../../OrthancFramework/Sources/Logging.h" +#include "../../OrthancFramework/Sources/MallocMemoryBuffer.h" #include "../../OrthancFramework/Sources/MetricsRegistry.h" #include "../Plugins/Engine/OrthancPlugins.h" @@ -682,13 +683,46 @@ ServerContext::StoreResult ServerContext::Store(std::string& resultPublicId, - DicomInstanceToStore& dicom, + DicomInstanceToStore& receivedDicom, StoreInstanceMode mode) - { + { + DicomInstanceToStore* dicom = &receivedDicom; + std::unique_ptr<DicomInstanceToStore> modifiedDicom; + + std::unique_ptr<MallocMemoryBuffer> raii(new MallocMemoryBuffer); + +#if ORTHANC_ENABLE_PLUGINS == 1 + if (HasPlugins()) + { + void* modifiedDicomBuffer = NULL; + size_t modifiedDicomBufferSize = 0; + + bool store = GetPlugins().ApplyReceivedInstanceCallbacks(receivedDicom.GetBufferData(), + receivedDicom.GetBufferSize(), + &modifiedDicomBuffer, + modifiedDicomBufferSize); + raii->Assign(modifiedDicomBuffer, modifiedDicomBufferSize, ::free); + + if (!store) + { + StoreResult result; + result.SetStatus(StoreStatus_FilteredOut); + return result; + } + + if (modifiedDicomBufferSize > 0 && modifiedDicomBuffer != NULL) + { + modifiedDicom.reset(DicomInstanceToStore::CreateFromBuffer(modifiedDicomBuffer, modifiedDicomBufferSize)); + modifiedDicom->SetOrigin(dicom->GetOrigin()); + dicom = modifiedDicom.get(); + } + } +#endif + if (!isIngestTranscoding_) { // No automated transcoding. This was the only path in Orthanc <= 1.6.1. - return StoreAfterTranscoding(resultPublicId, dicom, mode); + return StoreAfterTranscoding(resultPublicId, *dicom, mode); } else { @@ -697,7 +731,7 @@ bool transcode = false; DicomTransferSyntax sourceSyntax; - if (!dicom.LookupTransferSyntax(sourceSyntax) || + if (!dicom->LookupTransferSyntax(sourceSyntax) || sourceSyntax == ingestTransferSyntax_) { // Don't transcode if the incoming DICOM is already in the proper transfer syntax @@ -724,7 +758,7 @@ if (!transcode) { // No transcoding - return StoreAfterTranscoding(resultPublicId, dicom, mode); + return StoreAfterTranscoding(resultPublicId, *dicom, mode); } else { @@ -733,7 +767,7 @@ syntaxes.insert(ingestTransferSyntax_); IDicomTranscoder::DicomImage source; - source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize()); + source.SetExternalBuffer(dicom->GetBufferData(), dicom->GetBufferSize()); IDicomTranscoder::DicomImage transcoded; if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) @@ -741,7 +775,7 @@ std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); std::unique_ptr<DicomInstanceToStore> toStore(DicomInstanceToStore::CreateFromParsedDicomFile(*tmp)); - toStore->SetOrigin(dicom.GetOrigin()); + toStore->SetOrigin(dicom->GetOrigin()); StoreResult result = StoreAfterTranscoding(resultPublicId, *toStore, mode); assert(resultPublicId == tmp->GetHasher().HashInstance()); @@ -751,7 +785,7 @@ else { // Cannot transcode => store the original file - return StoreAfterTranscoding(resultPublicId, dicom, mode); + return StoreAfterTranscoding(resultPublicId, *dicom, mode); } } }