aboutsummaryrefslogtreecommitdiff
path: root/zenhttp/httpshared.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-11-07 10:18:44 +0100
committerGitHub <[email protected]>2022-11-07 01:18:44 -0800
commitbb07e58a9c59705b54164b06bcbe40c052880d90 (patch)
tree2b691d876b232f5354459a9c4a5cb44c21d541a8 /zenhttp/httpshared.cpp
parent0.1.8 (diff)
downloadzen-bb07e58a9c59705b54164b06bcbe40c052880d90.tar.xz
zen-bb07e58a9c59705b54164b06bcbe40c052880d90.zip
Support file reference in package message (#184)
* Fix packed message parsing for absolute path * Always enable are sharing when opening files as IoBuffers. * Allow control over sending partial files as localfile ref * Check "AcceptFlags" field in RPC message for allowing localfile ref in reply * make oplog entry add operations ZEN_DEBUG level logs * changelog
Diffstat (limited to 'zenhttp/httpshared.cpp')
-rw-r--r--zenhttp/httpshared.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/zenhttp/httpshared.cpp b/zenhttp/httpshared.cpp
index f9aa3af82..a7dca5441 100644
--- a/zenhttp/httpshared.cpp
+++ b/zenhttp/httpshared.cpp
@@ -6,14 +6,14 @@
#include <zencore/compactbinarypackage.h>
#include <zencore/compositebuffer.h>
#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
#include <zencore/iobuffer.h>
#include <zencore/iohash.h>
+#include <zencore/logging.h>
#include <zencore/stream.h>
#include <zencore/testing.h>
#include <zencore/testutils.h>
-#include <zencore/fmtutils.h>
-
#include <span>
#include <vector>
@@ -93,7 +93,10 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags)
ResponseBuffers.push_back(std::move(RefBuffer));
};
- auto IsLocalRef = [](const CompositeBuffer& AttachmentBinary, CbAttachmentReferenceHeader& LocalRef, std::string& Path8) -> bool {
+ auto IsLocalRef = [](const CompositeBuffer& AttachmentBinary,
+ bool DenyPartialLocalReferences,
+ CbAttachmentReferenceHeader& LocalRef,
+ std::string& Path8) -> bool {
const SharedBuffer& Segment = AttachmentBinary.GetSegments().front();
IoBufferFileReference Ref;
const IoBuffer& SegmentBuffer = Segment.AsIoBuffer();
@@ -103,6 +106,11 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags)
return false;
}
+ if (DenyPartialLocalReferences && !SegmentBuffer.IsWholeFile())
+ {
+ return false;
+ }
+
ExtendablePathBuilder<256> LocalRefFile;
LocalRefFile.Append(std::filesystem::absolute(PathFromHandle(Ref.FileHandle)));
Path8 = LocalRefFile.ToUtf8();
@@ -131,19 +139,20 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags)
// segments to be marshaled at once
bool MarshalByLocalRef = EnumHasAllFlags(Flags, FormatFlags::kAllowLocalReferences) && (Compressed.GetSegments().size() == 1);
-
+ bool DenyPartialLocalReferences = EnumHasAllFlags(Flags, FormatFlags::kDenyPartialLocalReferences);
CbAttachmentReferenceHeader LocalRef;
std::string Path8;
if (MarshalByLocalRef)
{
- MarshalByLocalRef = IsLocalRef(Compressed, LocalRef, Path8);
+ MarshalByLocalRef = IsLocalRef(Compressed, DenyPartialLocalReferences, LocalRef, Path8);
}
if (MarshalByLocalRef)
{
const bool IsCompressed = true;
MarshalLocal(Path8, LocalRef, AttachmentHash, IsCompressed);
+ ZEN_DEBUG("Marshalled '{}' as file of {} bytes", Path8, Compressed.GetSize());
}
else
{
@@ -171,19 +180,21 @@ FormatPackageMessage(const CbPackage& Data, FormatFlags Flags)
IoHash AttachmentHash = IoHash::FromBLAKE3(AttachmentBuffer.GetRawHash());
bool MarshalByLocalRef =
EnumHasAllFlags(Flags, FormatFlags::kAllowLocalReferences) && (AttachmentBinary.GetSegments().size() == 1);
+ bool DenyPartialLocalReferences = EnumHasAllFlags(Flags, FormatFlags::kDenyPartialLocalReferences);
CbAttachmentReferenceHeader LocalRef;
std::string Path8;
if (MarshalByLocalRef)
{
- MarshalByLocalRef = IsLocalRef(AttachmentBinary, LocalRef, Path8);
+ MarshalByLocalRef = IsLocalRef(AttachmentBinary, DenyPartialLocalReferences, LocalRef, Path8);
}
if (MarshalByLocalRef)
{
const bool IsCompressed = false;
MarshalLocal(Path8, LocalRef, AttachmentHash, IsCompressed);
+ ZEN_DEBUG("Marshalled '{}' as file of {} bytes", Path8, AttachmentBinary.GetSize());
}
else
{
@@ -270,7 +281,7 @@ ParsePackageMessage(IoBuffer Payload, std::function<IoBuffer(const IoHash&, uint
ZEN_ASSERT(AttachmentBuffer.Size() >= (sizeof(CbAttachmentReferenceHeader) + AttachRefHdr->AbsolutePathLength));
- std::filesystem::path Path{PathPointer};
+ std::filesystem::path Path{std::u8string_view(PathPointer, AttachRefHdr->AbsolutePathLength)};
if (IoBuffer ChunkReference =
IoBufferBuilder::MakeFromFile(Path, AttachRefHdr->PayloadByteOffset, AttachRefHdr->PayloadByteSize))