aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-03-14 14:36:18 +0100
committerGitHub <[email protected]>2023-03-14 06:36:18 -0700
commitfea4fa0095668e392aa3333450e93afc1784762b (patch)
treec80ffdf3824ba75ee9b7c312010cdb84c48aae46 /zenserver/cache/structuredcache.cpp
parentremoved catch2 (#241) (diff)
downloadzen-fea4fa0095668e392aa3333450e93afc1784762b.tar.xz
zen-fea4fa0095668e392aa3333450e93afc1784762b.zip
send payloads as duplicated handles (#240)
* send payloads as duplicated handles if requestor provides process id and allows local file references. * linux/macos fixes * tests * fix access rights when duplicating handle * fix closing of duplicated handles on error * cleanup * changelog
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 154676d77..8539d9c16 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -1306,7 +1306,8 @@ CbPackage
HttpStructuredCacheService::HandleRpcRequest(const ZenContentType ContentType,
IoBuffer&& Body,
uint32_t& OutAcceptMagic,
- RpcAcceptOptions& OutAcceptFlags)
+ RpcAcceptOptions& OutAcceptFlags,
+ int& OutTargetProcessId)
{
CbPackage Package;
CbObjectView Object;
@@ -1321,8 +1322,9 @@ HttpStructuredCacheService::HandleRpcRequest(const ZenContentType ContentType,
Package = ParsePackageMessage(Body);
Object = Package.GetObject();
}
- OutAcceptMagic = Object["Accept"sv].AsUInt32();
- OutAcceptFlags = static_cast<RpcAcceptOptions>(Object["AcceptFlags"sv].AsUInt16(0u));
+ OutAcceptMagic = Object["Accept"sv].AsUInt32();
+ OutAcceptFlags = static_cast<RpcAcceptOptions>(Object["AcceptFlags"sv].AsUInt16(0u));
+ OutTargetProcessId = Object["Pid"sv].AsInt32(0);
const std::string_view Method = Object["Method"sv].AsString();
@@ -1367,14 +1369,20 @@ HttpStructuredCacheService::ReplayRequestRecorder(cache::IRpcRequestReplayer& Re
{
uint32_t AcceptMagic = 0;
RpcAcceptOptions AcceptFlags = RpcAcceptOptions::kNone;
- CbPackage RpcResult = HandleRpcRequest(ContentType.first, std::move(Body), AcceptMagic, AcceptFlags);
+ int TargetPid = 0;
+ CbPackage RpcResult = HandleRpcRequest(ContentType.first, std::move(Body), AcceptMagic, AcceptFlags, TargetPid);
if (AcceptMagic == kCbPkgMagic)
{
- bool AllowFileReferences = EnumHasAllFlags(AcceptFlags, RpcAcceptOptions::kAllowLocalReferences);
- CompositeBuffer RpcResponseBuffer = FormatPackageMessageBuffer(
- RpcResult,
- AllowFileReferences ? FormatFlags::kAllowLocalReferences | FormatFlags::kDenyPartialLocalReferences
- : FormatFlags::kDefault);
+ FormatFlags Flags = FormatFlags::kDefault;
+ if (EnumHasAllFlags(AcceptFlags, RpcAcceptOptions::kAllowLocalReferences))
+ {
+ Flags |= FormatFlags::kAllowLocalReferences;
+ if (!EnumHasAnyFlags(AcceptFlags, RpcAcceptOptions::kAllowPartialLocalReferences))
+ {
+ Flags |= FormatFlags::kDenyPartialLocalReferences;
+ }
+ }
+ CompositeBuffer RpcResponseBuffer = FormatPackageMessageBuffer(RpcResult, Flags, TargetPid);
ZEN_ASSERT(RpcResponseBuffer.GetSize() > 0);
}
else
@@ -1417,9 +1425,10 @@ HttpStructuredCacheService::HandleRpcRequest(HttpServerRequest& Request)
[this, Body = Request.ReadPayload(), ContentType, AcceptType](HttpServerRequest& AsyncRequest) mutable {
std::uint64_t RequestIndex =
m_RequestRecorder ? m_RequestRecorder->RecordRequest(ContentType, AcceptType, Body) : ~0ull;
- uint32_t AcceptMagic = 0;
- RpcAcceptOptions AcceptFlags = RpcAcceptOptions::kNone;
- CbPackage RpcResult = HandleRpcRequest(ContentType, std::move(Body), AcceptMagic, AcceptFlags);
+ uint32_t AcceptMagic = 0;
+ RpcAcceptOptions AcceptFlags = RpcAcceptOptions::kNone;
+ int TargetProcessId = 0;
+ CbPackage RpcResult = HandleRpcRequest(ContentType, std::move(Body), AcceptMagic, AcceptFlags, TargetProcessId);
if (RpcResult.IsNull())
{
AsyncRequest.WriteResponse(HttpResponseCode::BadRequest);
@@ -1427,11 +1436,16 @@ HttpStructuredCacheService::HandleRpcRequest(HttpServerRequest& Request)
}
if (AcceptMagic == kCbPkgMagic)
{
- bool AllowFileReferences = EnumHasAllFlags(AcceptFlags, RpcAcceptOptions::kAllowLocalReferences);
- CompositeBuffer RpcResponseBuffer = FormatPackageMessageBuffer(
- RpcResult,
- AllowFileReferences ? FormatFlags::kAllowLocalReferences | FormatFlags::kDenyPartialLocalReferences
- : FormatFlags::kDefault);
+ FormatFlags Flags = FormatFlags::kDefault;
+ if (EnumHasAllFlags(AcceptFlags, RpcAcceptOptions::kAllowLocalReferences))
+ {
+ Flags |= FormatFlags::kAllowLocalReferences;
+ if (!EnumHasAnyFlags(AcceptFlags, RpcAcceptOptions::kAllowPartialLocalReferences))
+ {
+ Flags |= FormatFlags::kDenyPartialLocalReferences;
+ }
+ }
+ CompositeBuffer RpcResponseBuffer = FormatPackageMessageBuffer(RpcResult, Flags, TargetProcessId);
if (RequestIndex != ~0ull)
{
ZEN_ASSERT(m_RequestRecorder);