72 lines
2.8 KiB
C++
72 lines
2.8 KiB
C++
#pragma once
|
|
#include <larra/jid.hpp>
|
|
#include <larra/utils.hpp>
|
|
|
|
namespace larra::xmpp {
|
|
|
|
struct PlainUserAccount {
|
|
BareJid jid;
|
|
std::string password;
|
|
template <typename Self>
|
|
constexpr auto Jid(this Self&& self, BareJid value) {
|
|
return utils::FieldSetHelper::With<"jid", PlainUserAccount>(std::forward<Self>(self), std::move(value));
|
|
}
|
|
template <typename Self>
|
|
constexpr auto Password(this Self&& self, std::string value) {
|
|
return utils::FieldSetHelper::With<"password", PlainUserAccount>(std::forward<Self>(self), std::move(value));
|
|
}
|
|
};
|
|
|
|
struct EncryptionUserAccount : PlainUserAccount {
|
|
using PlainUserAccount::PlainUserAccount;
|
|
constexpr EncryptionUserAccount(PlainUserAccount base) : PlainUserAccount{std::move(base)} {};
|
|
constexpr EncryptionUserAccount(BareJid jid, std::string password) :
|
|
PlainUserAccount{.jid = std::move(jid), .password = std::move(password)} {};
|
|
};
|
|
|
|
struct EncryptionRequiredUserAccount : EncryptionUserAccount {
|
|
using EncryptionUserAccount::EncryptionUserAccount;
|
|
constexpr EncryptionRequiredUserAccount(PlainUserAccount base) : EncryptionUserAccount{std::move(base)} {};
|
|
constexpr EncryptionRequiredUserAccount(BareJid jid, std::string password) :
|
|
EncryptionUserAccount{std::move(jid), std::move(password)} {};
|
|
};
|
|
|
|
using UserAccountVariant = std::variant<PlainUserAccount, EncryptionUserAccount, EncryptionRequiredUserAccount>;
|
|
|
|
struct UserAccount : UserAccountVariant {
|
|
using UserAccountVariant::variant;
|
|
template <typename Self>
|
|
constexpr auto Jid(this Self&& self, BareJid value) -> UserAccount { // NOLINT(cppcoreguidelines-missing-std-forward)
|
|
return std::visit<UserAccount>(
|
|
[&](auto& ref) -> std::decay_t<decltype(ref)> {
|
|
return {std::forward_like<Self>(ref).Jid(std::move(value))};
|
|
},
|
|
self);
|
|
}
|
|
template <typename Self>
|
|
constexpr auto Password(this Self&& self, std::string value) -> UserAccount { // NOLINT(cppcoreguidelines-missing-std-forward)
|
|
return std::visit<UserAccount>(
|
|
[&](auto& ref) -> std::decay_t<decltype(ref)> {
|
|
return std::forward_like<Self>(ref).Password(std::move(value));
|
|
},
|
|
self);
|
|
}
|
|
template <typename Self>
|
|
constexpr auto Jid(this Self&& self) -> decltype(auto) { // NOLINT(cppcoreguidelines-missing-std-forward)
|
|
return std::visit<decltype(std::forward_like<Self>(std::declval<BareJid&>()))>(
|
|
[](auto& ref) -> decltype(auto) {
|
|
return std::forward_like<Self>(ref.jid);
|
|
},
|
|
self);
|
|
}
|
|
template <typename Self>
|
|
constexpr auto Password(this Self&& self) -> decltype(auto) { // NOLINT(cppcoreguidelines-missing-std-forward)
|
|
return std::visit<decltype(std::forward_like<Self>(std::declval<BareJid&>()))>(
|
|
[](auto& ref) -> decltype(auto) {
|
|
return std::forward_like<Self>(ref.password);
|
|
},
|
|
self);
|
|
}
|
|
};
|
|
|
|
} // namespace larra::xmpp
|