Add initiating new stream after SASL
This commit is contained in:
parent
0636e1c234
commit
ba03f3fe6f
3 changed files with 14 additions and 10 deletions
|
@ -235,7 +235,7 @@ struct ClientCreateVisitor {
|
|||
auto Auth(XmlStream<Socket>& stream, ServerToUserStream streamHeader, StreamFeatures features) -> boost::asio::awaitable<void> {
|
||||
co_return co_await std::visit(
|
||||
[&](auto& account) -> boost::asio::awaitable<void> {
|
||||
return this->Auth(std::move(account), stream, std::move(streamHeader), std::move(features));
|
||||
return this->Auth(account, stream, std::move(streamHeader), std::move(features));
|
||||
},
|
||||
this->account);
|
||||
}
|
||||
|
@ -293,7 +293,10 @@ struct ClientCreateVisitor {
|
|||
}
|
||||
|
||||
co_await this->Auth(stream, std::move(sToUStream), std::move(features));
|
||||
co_return Client{std::move(this->account).Jid(), std::move(stream)};
|
||||
co_await stream.Send(UserStream{.from = this->account.Jid(), .to = account.Jid().server, .version = "1.0", .xmlLang = "en"});
|
||||
ServerToUserStream secondSToUStream = co_await ReadStartStream(stream);
|
||||
StreamFeatures secondFeatures = co_await stream.template Read<StreamFeatures>();
|
||||
co_return Client{std::move(this->account.Jid()), std::move(stream)};
|
||||
}
|
||||
|
||||
template <typename Socket>
|
||||
|
@ -301,7 +304,9 @@ struct ClientCreateVisitor {
|
|||
-> boost::asio::awaitable<std::variant<Client<Socket>, Client<boost::asio::ssl::stream<Socket>>>> {
|
||||
auto& socket = stream.next_layer();
|
||||
co_await this->Connect(socket.next_layer(), co_await this->Resolve());
|
||||
co_await stream.Send(UserStream{.from = account.Jid().Username("anonymous"), .to = account.Jid().server}, socket.next_layer());
|
||||
co_await stream.Send(
|
||||
UserStream{.from = account.Jid().Username("anonymous"), .to = account.Jid().server, .version = "1.0", .xmlLang = "en"},
|
||||
socket.next_layer());
|
||||
SPDLOG_DEBUG("UserStream sended");
|
||||
auto streamHeader = co_await this->ReadStartStream(stream);
|
||||
StreamFeatures features = co_await stream.template Read<StreamFeatures>();
|
||||
|
@ -318,7 +323,9 @@ struct ClientCreateVisitor {
|
|||
auto newStreamHeader = co_await this->ReadStartStream(stream);
|
||||
auto newFeatures = co_await stream.template Read<StreamFeatures>();
|
||||
co_await this->Auth(stream, std::move(newStreamHeader), std::move(newFeatures));
|
||||
co_return Client{std::move(this->account).Jid(), XmlStream{std::move(socket)}};
|
||||
ServerToUserStream secondSToUStream = co_await ReadStartStream(stream);
|
||||
StreamFeatures secondFeatures = co_await stream.template Read<StreamFeatures>();
|
||||
co_return Client{std::move(this->account.Jid()), std::move(stream)};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ struct Serialization : SerializationBase<T> {
|
|||
try {
|
||||
return Serialization::StartCheck(element) ? std::optional{T::Parse(element)} : std::nullopt;
|
||||
} catch(const std::exception& e) {
|
||||
SPDLOG_WARN("Type {}: Failed Parse but no TryParse found: {}", e.what(), nameof::nameof_type<T>());
|
||||
SPDLOG_WARN("Type {}: Failed Parse but no TryParse found: {}", nameof::nameof_type<T>(), e.what());
|
||||
} catch(...) {
|
||||
SPDLOG_WARN("Type {}: Failed Parse but no TryParse found", nameof::nameof_type<T>());
|
||||
}
|
||||
|
|
|
@ -36,13 +36,10 @@ auto StreamFeatures::BindType::Parse(const xmlpp::Element* node) -> StreamFeatur
|
|||
|
||||
auto StreamFeatures::Parse(const xmlpp::Element* node) -> StreamFeatures {
|
||||
auto ptr = dynamic_cast<const xmlpp::Element*>(node->get_first_child("mechanisms"));
|
||||
if(!ptr) {
|
||||
throw std::runtime_error("Not found or invalid node mechanisms for StreamFeatures");
|
||||
}
|
||||
|
||||
using SaslMechanisms = struct SaslMechanisms;
|
||||
return {.startTls = ToOptional<StartTlsType>(node->get_first_child("starttls")),
|
||||
.bind = ToOptional<BindType>(node->get_first_child("bind")),
|
||||
.saslMechanisms = SaslMechanisms::Parse(ptr),
|
||||
.saslMechanisms = ptr ? SaslMechanisms::Parse(ptr) : SaslMechanisms{.mechanisms = {}},
|
||||
.others = node->get_children() | std::views::filter([](const xmlpp::Node* node) -> bool {
|
||||
auto name = node->get_name();
|
||||
return name != "starttls" && name != "mechanisms" && name != "bind";
|
||||
|
|
Loading…
Reference in a new issue