summaryrefslogtreecommitdiff
path: root/http/utility.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-02-10 05:08:23 +0300
committerEd Tanous <ed@tanous.net>2023-04-27 20:18:35 +0300
commit15a42df05b033a06e38d2998511d6c79d09d66a7 (patch)
tree9e21eba54b9d5783a5d233c69a345d9bb964123d /http/utility.hpp
parent02e01b5108d46720a0b438c0d79952464320d954 (diff)
downloadbmcweb-15a42df05b033a06e38d2998511d6c79d09d66a7.tar.xz
Remove number support from the router
The router historically came from crow. Crow supported wildcards of <int>, <float>, and <double>. bmcweb doesn't use them, nor should it in basically any case, as we now have explicit 404 handling. This commit removes them. This amounts to about -450 lines of code, but it's some of the scarier code we have, some of it existing in the namespace "black_magic". Reducing the brain debt for people working in this subsystem seems worthwhile. There is no case in the future where we would use integer based url parameters. Tested: Redfish service validator passes. Should be good enough coverage for a code removal. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I34add8df7d3486952474ca7ec3dc6be990c50ed0
Diffstat (limited to 'http/utility.hpp')
-rw-r--r--http/utility.hpp187
1 files changed, 8 insertions, 179 deletions
diff --git a/http/utility.hpp b/http/utility.hpp
index fd01bf1624..75c84c2fc8 100644
--- a/http/utility.hpp
+++ b/http/utility.hpp
@@ -34,12 +34,9 @@ namespace black_magic
enum class TypeCode : uint8_t
{
Unspecified = 0,
- Integer = 1,
- UnsignedInteger = 2,
- Float = 3,
- String = 4,
- Path = 5,
- Max = 6,
+ String = 1,
+ Path = 2,
+ Max = 3,
};
// Remove when we have c++23
@@ -49,60 +46,6 @@ constexpr typename std::underlying_type<E>::type toUnderlying(E e) noexcept
return static_cast<typename std::underlying_type<E>::type>(e);
}
-template <typename T>
-constexpr TypeCode getParameterTag()
-{
- if constexpr (std::is_same_v<int, T>)
- {
- return TypeCode::Integer;
- }
- if constexpr (std::is_same_v<char, T>)
- {
- return TypeCode::Integer;
- }
- if constexpr (std::is_same_v<short, T>)
- {
- return TypeCode::Integer;
- }
- if constexpr (std::is_same_v<long, T>)
- {
- return TypeCode::Integer;
- }
- if constexpr (std::is_same_v<long long, T>)
- {
- return TypeCode::Integer;
- }
- if constexpr (std::is_same_v<unsigned int, T>)
- {
- return TypeCode::UnsignedInteger;
- }
- if constexpr (std::is_same_v<unsigned char, T>)
- {
- return TypeCode::UnsignedInteger;
- }
- if constexpr (std::is_same_v<unsigned short, T>)
- {
- return TypeCode::UnsignedInteger;
- }
- if constexpr (std::is_same_v<unsigned long, T>)
- {
- return TypeCode::UnsignedInteger;
- }
- if constexpr (std::is_same_v<unsigned long long, T>)
- {
- return TypeCode::UnsignedInteger;
- }
- if constexpr (std::is_same_v<double, T>)
- {
- return TypeCode::Float;
- }
- if constexpr (std::is_same_v<std::string, T>)
- {
- return TypeCode::String;
- }
- return TypeCode::Unspecified;
-}
-
template <typename... Args>
struct computeParameterTagFromArgsList;
@@ -115,16 +58,10 @@ struct computeParameterTagFromArgsList<>
template <typename Arg, typename... Args>
struct computeParameterTagFromArgsList<Arg, Args...>
{
+ static_assert(std::is_same_v<std::string, std::decay_t<Arg>>);
static constexpr int subValue =
computeParameterTagFromArgsList<Args...>::value;
- static constexpr int value =
- getParameterTag<typename std::decay<Arg>::type>() !=
- TypeCode::Unspecified
- ? static_cast<unsigned long>(subValue *
- toUnderlying(TypeCode::Max)) +
- static_cast<uint64_t>(
- getParameterTag<typename std::decay<Arg>::type>())
- : subValue;
+ static constexpr int value = subValue * toUnderlying(TypeCode::String);
};
inline bool isParameterTagCompatible(uint64_t a, uint64_t b)
@@ -196,22 +133,9 @@ constexpr inline uint64_t getParameterTag(std::string_view url)
uint64_t insertIndex = 1;
for (size_t unused = 0; unused < paramIndex; unused++)
{
- insertIndex *= 6;
+ insertIndex *= 3;
}
- if (tag == "<int>")
- {
- tagValue += insertIndex * toUnderlying(TypeCode::Integer);
- }
- if (tag == "<uint>")
- {
- tagValue +=
- insertIndex * toUnderlying(TypeCode::UnsignedInteger);
- }
- if (tag == "<float>" || tag == "<double>")
- {
- tagValue += insertIndex * toUnderlying(TypeCode::Float);
- }
if (tag == "<str>" || tag == "<string>")
{
tagValue += insertIndex * toUnderlying(TypeCode::String);
@@ -258,46 +182,11 @@ struct CallHelper<F, S<Args...>>
static constexpr bool value = sizeof(test<F, Args...>(0)) == sizeof(char);
};
-template <uint64_t N>
-struct SingleTagToType
-{};
-
-template <>
-struct SingleTagToType<1>
-{
- using type = int64_t;
-};
-
-template <>
-struct SingleTagToType<2>
-{
- using type = uint64_t;
-};
-
-template <>
-struct SingleTagToType<3>
-{
- using type = double;
-};
-
-template <>
-struct SingleTagToType<4>
-{
- using type = std::string;
-};
-
-template <>
-struct SingleTagToType<5>
-{
- using type = std::string;
-};
-
template <uint64_t Tag>
struct Arguments
{
- using subarguments = typename Arguments<Tag / 6>::type;
- using type = typename subarguments::template push<
- typename SingleTagToType<Tag % 6>::type>;
+ using subarguments = typename Arguments<Tag / 3>::type;
+ using type = typename subarguments::template push<std::string>;
};
template <>
@@ -306,66 +195,6 @@ struct Arguments<0>
using type = S<>;
};
-template <typename T>
-struct Promote
-{
- using type = T;
-};
-
-template <typename T>
-using PromoteT = typename Promote<T>::type;
-
-template <>
-struct Promote<char>
-{
- using type = int64_t;
-};
-template <>
-struct Promote<short>
-{
- using type = int64_t;
-};
-template <>
-struct Promote<int>
-{
- using type = int64_t;
-};
-template <>
-struct Promote<long>
-{
- using type = int64_t;
-};
-template <>
-struct Promote<long long>
-{
- using type = int64_t;
-};
-template <>
-struct Promote<unsigned char>
-{
- using type = uint64_t;
-};
-template <>
-struct Promote<unsigned short>
-{
- using type = uint64_t;
-};
-template <>
-struct Promote<unsigned int>
-{
- using type = uint64_t;
-};
-template <>
-struct Promote<unsigned long>
-{
- using type = uint64_t;
-};
-template <>
-struct Promote<unsigned long long>
-{
- using type = uint64_t;
-};
-
} // namespace black_magic
namespace utility