Compare commits

..

No commits in common. "main" and "feature_message_roster" have entirely different histories.

2 changed files with 80 additions and 81 deletions

View file

@ -58,17 +58,19 @@ struct Type : TypeVariant {
}; };
struct StanzaErrorBase : std::exception {}; struct StanzaErrorBase : std::exception {};
namespace impl {
// DO NOT MOVE TO ANOTHER NAMESPACE(where no heirs). VIA friend A FUNCTION IS ADDED THAT VIA ADL WILL BE SEARCHED FOR HEIRS
// C++20 modules very unstable in clangd :(
template <typename T, typename Default> template <typename T, typename Default>
struct StanzaError : StanzaErrorBase { struct StanzaErrorImpl : StanzaErrorBase {
static constexpr auto kDefaultName = "error"; static constexpr auto kDefaultName = "error";
static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas"; static constexpr auto kDefaultNamespace = "urn:ietf:params:xml:ns:xmpp-stanzas";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>()); static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
constexpr StanzaError(std::optional<std::string> by, Type type) : by(std::move(by)), type(std::move(type)) { constexpr StanzaErrorImpl(std::optional<std::string> by, Type type) : by(std::move(by)), type(std::move(type)) {
} }
constexpr StanzaError() = default; constexpr StanzaErrorImpl() = default;
struct FieldInfo { struct FieldInfo {
using Main = StanzaError; using Main = StanzaErrorImpl;
using Info = serialization::MetaInfo<Main>; using Info = serialization::MetaInfo<Main>;
using Type = Type; using Type = Type;
static inline const std::string kName = "type"; static inline const std::string kName = "type";
@ -119,7 +121,7 @@ struct StanzaError : StanzaErrorBase {
auto node = element->add_child_element(kKebabCaseName); auto node = element->add_child_element(kKebabCaseName);
node->set_namespace_declaration(kDefaultNamespace); node->set_namespace_declaration(kDefaultNamespace);
} }
constexpr auto operator==(const StanzaError&) const -> bool { constexpr auto operator==(const StanzaErrorImpl&) const -> bool {
return true; return true;
}; };
[[nodiscard]] constexpr auto what() const noexcept -> const char* override { [[nodiscard]] constexpr auto what() const noexcept -> const char* override {
@ -127,8 +129,6 @@ struct StanzaError : StanzaErrorBase {
} }
}; };
} // namespace impl
// Helper class to prevent parsing response stream into an expected return type if its name is an 'error' // Helper class to prevent parsing response stream into an expected return type if its name is an 'error'
struct UnknownStanzaError : StanzaErrorBase { struct UnknownStanzaError : StanzaErrorBase {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
@ -151,71 +151,71 @@ struct UnknownStanzaError : StanzaErrorBase {
} }
}; };
struct BadRequest : impl::StanzaError<BadRequest, type::Modify> { struct BadRequest : StanzaErrorImpl<BadRequest, type::Modify> {
using impl::StanzaError<BadRequest, type::Modify>::StanzaError; using StanzaErrorImpl<BadRequest, type::Modify>::StanzaErrorImpl;
}; };
struct Conflict : impl::StanzaError<Conflict, type::Cancel> { struct Conflict : StanzaErrorImpl<Conflict, type::Cancel> {
using impl::StanzaError<Conflict, type::Cancel>::StanzaError; using StanzaErrorImpl<Conflict, type::Cancel>::StanzaErrorImpl;
}; };
struct FeatureNotImplemented : impl::StanzaError<FeatureNotImplemented, type::Cancel> { struct FeatureNotImplemented : StanzaErrorImpl<FeatureNotImplemented, type::Cancel> {
using impl::StanzaError<FeatureNotImplemented, type::Cancel>::StanzaError; using StanzaErrorImpl<FeatureNotImplemented, type::Cancel>::StanzaErrorImpl;
}; };
struct Forbidden : impl::StanzaError<Forbidden, type::Auth> { struct Forbidden : StanzaErrorImpl<Forbidden, type::Auth> {
using impl::StanzaError<Forbidden, type::Auth>::StanzaError; using StanzaErrorImpl<Forbidden, type::Auth>::StanzaErrorImpl;
}; };
struct Gone : impl::StanzaError<Gone, type::Cancel> { struct Gone : StanzaErrorImpl<Gone, type::Cancel> {
using impl::StanzaError<Gone, type::Cancel>::StanzaError; using StanzaErrorImpl<Gone, type::Cancel>::StanzaErrorImpl;
}; };
struct InternalServerError : impl::StanzaError<InternalServerError, type::Cancel> { struct InternalServerError : StanzaErrorImpl<InternalServerError, type::Cancel> {
using impl::StanzaError<InternalServerError, type::Cancel>::StanzaError; using StanzaErrorImpl<InternalServerError, type::Cancel>::StanzaErrorImpl;
}; };
struct ItemNotFound : impl::StanzaError<ItemNotFound, type::Cancel> { struct ItemNotFound : StanzaErrorImpl<ItemNotFound, type::Cancel> {
using impl::StanzaError<ItemNotFound, type::Cancel>::StanzaError; using StanzaErrorImpl<ItemNotFound, type::Cancel>::StanzaErrorImpl;
}; };
struct JidMalformed : impl::StanzaError<JidMalformed, type::Modify> { struct JidMalformed : StanzaErrorImpl<JidMalformed, type::Modify> {
using impl::StanzaError<JidMalformed, type::Modify>::StanzaError; using StanzaErrorImpl<JidMalformed, type::Modify>::StanzaErrorImpl;
}; };
struct NotAcceptable : impl::StanzaError<NotAcceptable, type::Modify> { struct NotAcceptable : StanzaErrorImpl<NotAcceptable, type::Modify> {
using impl::StanzaError<NotAcceptable, type::Modify>::StanzaError; using StanzaErrorImpl<NotAcceptable, type::Modify>::StanzaErrorImpl;
}; };
struct NotAllowed : impl::StanzaError<NotAllowed, type::Cancel> { struct NotAllowed : StanzaErrorImpl<NotAllowed, type::Cancel> {
using impl::StanzaError<NotAllowed, type::Cancel>::StanzaError; using StanzaErrorImpl<NotAllowed, type::Cancel>::StanzaErrorImpl;
}; };
struct NotAuthorized : impl::StanzaError<NotAuthorized, type::Auth> { struct NotAuthorized : StanzaErrorImpl<NotAuthorized, type::Auth> {
using impl::StanzaError<NotAuthorized, type::Auth>::StanzaError; using StanzaErrorImpl<NotAuthorized, type::Auth>::StanzaErrorImpl;
}; };
struct PolicyViolation : impl::StanzaError<PolicyViolation, type::Modify> { struct PolicyViolation : StanzaErrorImpl<PolicyViolation, type::Modify> {
using impl::StanzaError<PolicyViolation, type::Modify>::StanzaError; using StanzaErrorImpl<PolicyViolation, type::Modify>::StanzaErrorImpl;
}; };
struct RecipientUnavailable : impl::StanzaError<RecipientUnavailable, type::Wait> { struct RecipientUnavailable : StanzaErrorImpl<RecipientUnavailable, type::Wait> {
using impl::StanzaError<RecipientUnavailable, type::Wait>::StanzaError; using StanzaErrorImpl<RecipientUnavailable, type::Wait>::StanzaErrorImpl;
}; };
struct Redirect : impl::StanzaError<Redirect, type::Modify> { struct Redirect : StanzaErrorImpl<Redirect, type::Modify> {
using impl::StanzaError<Redirect, type::Modify>::StanzaError; using StanzaErrorImpl<Redirect, type::Modify>::StanzaErrorImpl;
}; };
struct RegistrationRequired : impl::StanzaError<RegistrationRequired, type::Auth> { struct RegistrationRequired : StanzaErrorImpl<RegistrationRequired, type::Auth> {
using impl::StanzaError<RegistrationRequired, type::Auth>::StanzaError; using StanzaErrorImpl<RegistrationRequired, type::Auth>::StanzaErrorImpl;
}; };
struct RemoteServerNotFound : impl::StanzaError<RemoteServerNotFound, type::Cancel> { struct RemoteServerNotFound : StanzaErrorImpl<RemoteServerNotFound, type::Cancel> {
using impl::StanzaError<RemoteServerNotFound, type::Cancel>::StanzaError; using StanzaErrorImpl<RemoteServerNotFound, type::Cancel>::StanzaErrorImpl;
}; };
struct RemoteServerTimeout : impl::StanzaError<RemoteServerTimeout, type::Wait> { struct RemoteServerTimeout : StanzaErrorImpl<RemoteServerTimeout, type::Wait> {
using impl::StanzaError<RemoteServerTimeout, type::Wait>::StanzaError; using StanzaErrorImpl<RemoteServerTimeout, type::Wait>::StanzaErrorImpl;
}; };
struct ResourceConstraint : impl::StanzaError<ResourceConstraint, type::Wait> { struct ResourceConstraint : StanzaErrorImpl<ResourceConstraint, type::Wait> {
using impl::StanzaError<ResourceConstraint, type::Wait>::StanzaError; using StanzaErrorImpl<ResourceConstraint, type::Wait>::StanzaErrorImpl;
}; };
struct ServiceUnavailable : impl::StanzaError<ServiceUnavailable, type::Cancel> { struct ServiceUnavailable : StanzaErrorImpl<ServiceUnavailable, type::Cancel> {
using impl::StanzaError<ServiceUnavailable, type::Cancel>::StanzaError; using StanzaErrorImpl<ServiceUnavailable, type::Cancel>::StanzaErrorImpl;
}; };
struct SubscriptionRequired : impl::StanzaError<SubscriptionRequired, type::Auth> { struct SubscriptionRequired : StanzaErrorImpl<SubscriptionRequired, type::Auth> {
using impl::StanzaError<SubscriptionRequired, type::Auth>::StanzaError; using StanzaErrorImpl<SubscriptionRequired, type::Auth>::StanzaErrorImpl;
}; };
struct UndefinedCondition : impl::StanzaError<UndefinedCondition, type::Modify> { struct UndefinedCondition : StanzaErrorImpl<UndefinedCondition, type::Modify> {
using impl::StanzaError<UndefinedCondition, type::Modify>::StanzaError; using StanzaErrorImpl<UndefinedCondition, type::Modify>::StanzaErrorImpl;
}; };
struct UnexpectedRequest : impl::StanzaError<UnexpectedRequest, type::Modify> { struct UnexpectedRequest : StanzaErrorImpl<UnexpectedRequest, type::Modify> {
using impl::StanzaError<UnexpectedRequest, type::Modify>::StanzaError; using StanzaErrorImpl<UnexpectedRequest, type::Modify>::StanzaErrorImpl;
}; };
using StanzaError = std::variant<BadRequest, using StanzaError = std::variant<BadRequest,

View file

@ -10,9 +10,10 @@ namespace error::stream {
struct BaseError : std::exception {}; struct BaseError : std::exception {};
namespace impl { // DO NOT MOVE TO ANOTHER NAMESPACE(where no heirs). VIA friend A FUNCTION IS ADDED THAT VIA ADL WILL BE SEARCHED FOR HEIRS
// C++20 modules very unstable in clangd :(
template <typename T> template <typename T>
struct Error : BaseError { struct ErrorImpl : BaseError {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>()); static inline const auto kKebabCaseName = static_cast<std::string>(utils::ToKebabCaseName<T>());
@ -39,8 +40,6 @@ struct Error : BaseError {
} }
}; };
} // namespace impl
// Helper class to prevent parsing response stream into an expected return type if its name is a 'stream:error' // Helper class to prevent parsing response stream into an expected return type if its name is a 'stream:error'
struct UnknownXmppError : BaseError { struct UnknownXmppError : BaseError {
static constexpr auto kDefaultName = "stream:error"; static constexpr auto kDefaultName = "stream:error";
@ -60,31 +59,31 @@ struct UnknownXmppError : BaseError {
} }
}; };
struct BadFormat : impl::Error<BadFormat> {}; struct BadFormat : ErrorImpl<BadFormat> {};
struct BadNamespacePrefix : impl::Error<BadNamespacePrefix> {}; struct BadNamespacePrefix : ErrorImpl<BadNamespacePrefix> {};
struct Conflict : impl::Error<Conflict> {}; struct Conflict : ErrorImpl<Conflict> {};
struct ConnectionTimeout : impl::Error<ConnectionTimeout> {}; struct ConnectionTimeout : ErrorImpl<ConnectionTimeout> {};
struct HostGone : impl::Error<HostGone> {}; struct HostGone : ErrorImpl<HostGone> {};
struct HostUnknown : impl::Error<HostUnknown> {}; struct HostUnknown : ErrorImpl<HostUnknown> {};
struct ImproperAdressing : impl::Error<ImproperAdressing> {}; struct ImproperAdressing : ErrorImpl<ImproperAdressing> {};
struct InternalServerError : impl::Error<InternalServerError> {}; struct InternalServerError : ErrorImpl<InternalServerError> {};
struct InvalidFrom : impl::Error<InvalidFrom> {}; struct InvalidFrom : ErrorImpl<InvalidFrom> {};
struct InvalidNamespace : impl::Error<InvalidNamespace> {}; struct InvalidNamespace : ErrorImpl<InvalidNamespace> {};
struct InvalidXml : impl::Error<InvalidXml> {}; struct InvalidXml : ErrorImpl<InvalidXml> {};
struct NotAuthorized : impl::Error<NotAuthorized> {}; struct NotAuthorized : ErrorImpl<NotAuthorized> {};
struct NotWellFormed : impl::Error<NotWellFormed> {}; struct NotWellFormed : ErrorImpl<NotWellFormed> {};
struct PolicyViolation : impl::Error<PolicyViolation> {}; struct PolicyViolation : ErrorImpl<PolicyViolation> {};
struct RemoteConnectionFailed : impl::Error<RemoteConnectionFailed> {}; struct RemoteConnectionFailed : ErrorImpl<RemoteConnectionFailed> {};
struct Reset : impl::Error<Reset> {}; struct Reset : ErrorImpl<Reset> {};
struct ResourceConstraint : impl::Error<ResourceConstraint> {}; struct ResourceConstraint : ErrorImpl<ResourceConstraint> {};
struct RestrictedXml : impl::Error<RestrictedXml> {}; struct RestrictedXml : ErrorImpl<RestrictedXml> {};
struct SeeOtherHost : impl::Error<SeeOtherHost> {}; struct SeeOtherHost : ErrorImpl<SeeOtherHost> {};
struct SystemShutdown : impl::Error<SystemShutdown> {}; struct SystemShutdown : ErrorImpl<SystemShutdown> {};
struct UndefinedCondition : impl::Error<UndefinedCondition> {}; struct UndefinedCondition : ErrorImpl<UndefinedCondition> {};
struct UnsupportedEncoding : impl::Error<UnsupportedEncoding> {}; struct UnsupportedEncoding : ErrorImpl<UnsupportedEncoding> {};
struct UnsupportedFeature : impl::Error<UnsupportedFeature> {}; struct UnsupportedFeature : ErrorImpl<UnsupportedFeature> {};
struct UnsupportedStanzaType : impl::Error<UnsupportedStanzaType> {}; struct UnsupportedStanzaType : ErrorImpl<UnsupportedStanzaType> {};
struct UnsupportedVersion : impl::Error<UnsupportedVersion> {}; struct UnsupportedVersion : ErrorImpl<UnsupportedVersion> {};
} // namespace error::stream } // namespace error::stream