2024-11-25 13:19:02 +00:00
|
|
|
#include <larra/bind.hpp>
|
|
|
|
|
|
|
|
namespace larra::xmpp::iq {
|
|
|
|
auto operator<<(xmlpp::Element* element, const Bind& bind) -> void {
|
2024-12-19 17:18:52 +00:00
|
|
|
element->set_namespace_declaration(Bind::kDefaultNamespace);
|
2024-11-25 13:19:02 +00:00
|
|
|
|
|
|
|
if(bind.jid) {
|
|
|
|
auto* jid_el = element->add_child_element("jid");
|
|
|
|
jid_el->add_child_text(ToString(*bind.jid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[[nodiscard]] auto Bind::Parse(xmlpp::Element* element) -> Bind {
|
|
|
|
const auto* jid_node = element->get_first_child("jid");
|
|
|
|
if(!jid_node) {
|
|
|
|
SPDLOG_DEBUG("No Jid Node at Iq::Bind");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* jid_el = dynamic_cast<const xmlpp::Element*>(jid_node);
|
|
|
|
if(!jid_el) {
|
|
|
|
throw std::runtime_error("dynamic_cast to const xmlpp::Element* failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto* text = jid_el->get_first_child_text();
|
|
|
|
if(!jid_el) {
|
|
|
|
throw std::runtime_error("No text at Iq::Bind jid child");
|
|
|
|
}
|
|
|
|
|
|
|
|
return {.jid = (jid_node ? std::optional{FullJid::Parse(text->get_content())} : std::nullopt)};
|
|
|
|
}
|
|
|
|
} // namespace larra::xmpp::iq
|