Skip to content

Commit

Permalink
translation/Parser: move code to HandleAllowRemoteNetwork()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 1, 2024
1 parent 23cb6ee commit 490f9d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/translation/Parser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,25 @@ TranslateParser::HandleMountListenStream(std::span<const std::byte> payload)

#endif // TRANSLATION_ENABLE_SPAWN

#if TRANSLATION_ENABLE_HTTP

inline void
TranslateParser::HandleAllowRemoteNetwork(std::span<const std::byte> payload)
{
if (payload.size() < 2)
throw std::runtime_error{"malformed ALLOW_REMOTE_NETWORK packet"};

const uint_least8_t prefix_length = static_cast<uint8_t>(payload.front());
const SocketAddress address{
reinterpret_cast<const struct sockaddr *>(payload.data() + 1),
static_cast<SocketAddress::size_type>(payload.size() - 1),
};

response.allow_remote_networks.Add(alloc, address, prefix_length);
}

#endif // TRANSLATION_ENABLE_HTTP

static bool
CheckProbeSuffix(std::string_view payload) noexcept
{
Expand Down Expand Up @@ -4294,12 +4313,7 @@ TranslateParser::HandleRegularPacket(TranslationCommand command,

case TranslationCommand::ALLOW_REMOTE_NETWORK:
#if TRANSLATION_ENABLE_HTTP
if (payload.size() < 2)
throw std::runtime_error{"malformed ALLOW_REMOTE_NETWORK packet"};

response.allow_remote_networks.Add(alloc,
SocketAddress(reinterpret_cast<const struct sockaddr *>(payload.data() + 1), payload.size() - 1),
static_cast<uint8_t>(payload.front()));
HandleAllowRemoteNetwork(payload);
return;
#else
break;
Expand Down
4 changes: 4 additions & 0 deletions src/translation/Parser.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ private:

void HandleMountListenStream(std::span<const std::byte> payload);

#if TRANSLATION_ENABLE_HTTP
void HandleAllowRemoteNetwork(std::span<const std::byte> payload);
#endif

Result HandlePacket(TranslationCommand command,
std::span<const std::byte> payload);
};

0 comments on commit 490f9d1

Please sign in to comment.