Files
EchoionApi/include/echoion/api/plugin/ShortUrlSupport.hpp

53 lines
2.0 KiB
C++

#pragma once
#include <Void/Data/Json.hpp>
#include <cstdint>
#include <expected>
#include <optional>
#include <string>
#include <string_view>
namespace Echoion::Api::Plugin::ShortUrl
{
template <typename T> using Result = std::expected<T, std::string>;
[[nodiscard]] Result<Void::Json::Value>
parseConfigObject(const char* config);
[[nodiscard]] Result<std::string>
requireString(const Void::Json::Value& object, std::string_view key);
[[nodiscard]] Result<std::string>
optionalString(const Void::Json::Value& object, std::string_view key,
std::string_view fallback = {});
[[nodiscard]] Result<bool> optionalBool(const Void::Json::Value& object,
std::string_view key,
bool fallback);
[[nodiscard]] Result<std::int64_t>
optionalInteger(const Void::Json::Value& object, std::string_view key,
std::int64_t fallback, std::int64_t minimum,
std::int64_t maximum);
[[nodiscard]] bool
containsControlCharacters(std::string_view value) noexcept;
[[nodiscard]] std::string trimAscii(std::string_view value);
[[nodiscard]] bool isHeaderName(std::string_view value) noexcept;
[[nodiscard]] bool isBase62(std::string_view value) noexcept;
/// Validate an absolute HTTP(S) URL without making a network request.
[[nodiscard]] Result<void>
validateHttpUrl(std::string_view value, bool requireHttps,
std::size_t maximumLength = 8192);
/// Reject address literals and well-known hostnames that are not publicly
/// routable. DNS-backed validation lives in the external provider because
/// only it opens outbound connections.
[[nodiscard]] bool isObviouslyPrivateHost(std::string_view host) noexcept;
/// Expand ${url} and ${env:NAME}. Environment variables are read without
/// being copied into diagnostics; a missing variable reports only its name.
[[nodiscard]] Result<std::string>
expandTemplate(std::string_view input, std::string_view url,
bool encodeSubstitutions = false);
} // namespace Echoion::Api::Plugin::ShortUrl