Compare commits
1 commit
d88f14a66d
...
54b3535ebc
Author | SHA1 | Date | |
---|---|---|---|
54b3535ebc |
3 changed files with 11 additions and 59 deletions
|
@ -80,35 +80,21 @@ struct Client {
|
||||||
|
|
||||||
auto CreateResourceBind() -> boost::asio::awaitable<void> {
|
auto CreateResourceBind() -> boost::asio::awaitable<void> {
|
||||||
SPDLOG_INFO("Send IQ: Set::Bind");
|
SPDLOG_INFO("Send IQ: Set::Bind");
|
||||||
co_await this->Send(::iq::SetBind{.id = "1", .payload = {}});
|
co_await this->Send(::iq::SetBind{.id = "1", .payload = ::iq::Bind{}});
|
||||||
|
|
||||||
auto set_bind_response = co_await connection.template Read<Iq<::iq::Bind>>();
|
auto bind_result = co_await connection.template Read<::iq::ResultBind>();
|
||||||
std::visit(utempl::Overloaded(
|
jid.resource = std::move(bind_result.payload.jid->resource);
|
||||||
[](auto error) {
|
|
||||||
throw "Error response on IQ: Set::Bind: ''"; // TODO(unknown): Add exact error parsing
|
|
||||||
},
|
|
||||||
[&](::iq::ResultBind r) {
|
|
||||||
jid.resource = std::move(r.payload.jid->resource);
|
|
||||||
SPDLOG_INFO("Allocated resource: {}", jid.resource);
|
|
||||||
}),
|
|
||||||
set_bind_response);
|
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
|
auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
|
||||||
SPDLOG_INFO("Send IQ: Get::Roster");
|
SPDLOG_INFO("Send IQ: Get::Roster");
|
||||||
co_await this->Send(::iq::GetRoster{.id = "1", .from = std::format("{}@{}", "invalid_user", jid.server), .payload = {}});
|
co_await this->Send(::iq::GetRoster{.id = "1", .from = ToString(jid), .payload = ::iq::Roster{}});
|
||||||
|
|
||||||
const auto get_roster_response = co_await connection.template Read<Iq<::iq::Roster>>();
|
const auto roster_result = co_await connection.template Read<::iq::ResultRoster>();
|
||||||
std::visit(utempl::Overloaded(
|
roster = std::move(roster_result.payload);
|
||||||
[](auto error) {
|
|
||||||
throw "Error response on IQ: Get::Roster: ''"; // TODO(unknown): Add exact error parsing
|
SPDLOG_INFO("New roster: {}", ToString(roster));
|
||||||
},
|
|
||||||
[&](::iq::ResultRoster r) {
|
|
||||||
roster = std::move(r.payload);
|
|
||||||
SPDLOG_INFO("New roster: {}", ToString(roster));
|
|
||||||
}),
|
|
||||||
get_roster_response);
|
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,19 +48,6 @@ struct BaseImplWithPayload {
|
||||||
S::Serialize(element->add_child_element(S::kDefaultName, S::kPrefix), self.payload);
|
S::Serialize(element->add_child_element(S::kDefaultName, S::kPrefix), self.payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<BaseImplWithPayload> {
|
|
||||||
return [&] -> std::optional<BaseImplWithPayload> {
|
|
||||||
auto node = element->get_attribute("type");
|
|
||||||
if(!node) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
if(node->get_value() != Name) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return Parse(element);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> BaseImplWithPayload {
|
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> BaseImplWithPayload {
|
||||||
auto node = element->get_attribute("type");
|
auto node = element->get_attribute("type");
|
||||||
if(!node) {
|
if(!node) {
|
||||||
|
@ -91,7 +78,6 @@ struct BaseImplWithPayload {
|
||||||
.payload = S::Parse(payload2)};
|
.payload = S::Parse(payload2)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto kGetName = "get";
|
static constexpr auto kGetName = "get";
|
||||||
|
|
||||||
template <typename Payload>
|
template <typename Payload>
|
||||||
|
|
|
@ -73,25 +73,6 @@ struct ErrorImpl : BaseError {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper class to prevent parsing response stream into an expected return type if its name is a 'stream:error'
|
|
||||||
struct UnknownXmppError : BaseError {
|
|
||||||
static constexpr auto kDefaultName = "stream:error";
|
|
||||||
static constexpr std::string_view kErrorMessage = "Unknown XMPP stream error";
|
|
||||||
|
|
||||||
static constexpr auto TryParse(xmlpp::Element* element) {
|
|
||||||
return std::optional{UnknownXmppError{}};
|
|
||||||
}
|
|
||||||
static constexpr auto Parse(xmlpp::Element* element) {
|
|
||||||
return TryParse(element).value();
|
|
||||||
}
|
|
||||||
friend constexpr auto operator<<(xmlpp::Element* element, const UnknownXmppError& obj) -> void {
|
|
||||||
throw std::format("'{}' must never be written into the real stream!", kErrorMessage);
|
|
||||||
}
|
|
||||||
[[nodiscard]] constexpr auto what() const noexcept -> const char* override {
|
|
||||||
return kErrorMessage.data();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BadFormat : ErrorImpl<BadFormat> {};
|
struct BadFormat : ErrorImpl<BadFormat> {};
|
||||||
struct BadNamespacePrefix : ErrorImpl<BadNamespacePrefix> {};
|
struct BadNamespacePrefix : ErrorImpl<BadNamespacePrefix> {};
|
||||||
struct Conflict : ErrorImpl<Conflict> {};
|
struct Conflict : ErrorImpl<Conflict> {};
|
||||||
|
@ -100,7 +81,7 @@ struct HostGone : ErrorImpl<HostGone> {};
|
||||||
struct HostUnknown : ErrorImpl<HostUnknown> {};
|
struct HostUnknown : ErrorImpl<HostUnknown> {};
|
||||||
struct ImproperAdressing : ErrorImpl<ImproperAdressing> {};
|
struct ImproperAdressing : ErrorImpl<ImproperAdressing> {};
|
||||||
struct InternalServerError : ErrorImpl<InternalServerError> {};
|
struct InternalServerError : ErrorImpl<InternalServerError> {};
|
||||||
struct InvalidFrom : ErrorImpl<InvalidFrom> {};
|
struct InvalidForm : ErrorImpl<InvalidForm> {};
|
||||||
struct InvalidNamespace : ErrorImpl<InvalidNamespace> {};
|
struct InvalidNamespace : ErrorImpl<InvalidNamespace> {};
|
||||||
struct InvalidXml : ErrorImpl<InvalidXml> {};
|
struct InvalidXml : ErrorImpl<InvalidXml> {};
|
||||||
struct NotAuthorized : ErrorImpl<NotAuthorized> {};
|
struct NotAuthorized : ErrorImpl<NotAuthorized> {};
|
||||||
|
@ -128,7 +109,7 @@ using StreamError = std::variant<error::stream::BadFormat,
|
||||||
error::stream::HostUnknown,
|
error::stream::HostUnknown,
|
||||||
error::stream::ImproperAdressing,
|
error::stream::ImproperAdressing,
|
||||||
error::stream::InternalServerError,
|
error::stream::InternalServerError,
|
||||||
error::stream::InvalidFrom,
|
error::stream::InvalidForm,
|
||||||
error::stream::InvalidNamespace,
|
error::stream::InvalidNamespace,
|
||||||
error::stream::InvalidXml,
|
error::stream::InvalidXml,
|
||||||
error::stream::NotAuthorized,
|
error::stream::NotAuthorized,
|
||||||
|
@ -142,7 +123,6 @@ using StreamError = std::variant<error::stream::BadFormat,
|
||||||
error::stream::UnsupportedEncoding,
|
error::stream::UnsupportedEncoding,
|
||||||
error::stream::UnsupportedFeature,
|
error::stream::UnsupportedFeature,
|
||||||
error::stream::UnsupportedStanzaType,
|
error::stream::UnsupportedStanzaType,
|
||||||
error::stream::UnsupportedVersion,
|
error::stream::UnsupportedVersion>;
|
||||||
error::stream::UnknownXmppError>;
|
|
||||||
|
|
||||||
} // namespace larra::xmpp
|
} // namespace larra::xmpp
|
||||||
|
|
Loading…
Reference in a new issue