tmp2
This commit is contained in:
parent
c77614992d
commit
7078c25c2a
5 changed files with 103 additions and 90 deletions
|
@ -10,7 +10,7 @@ FROM archlinux@sha256:a10e51dd0694d6c4142754e9d06cbce7baf91ace8031a30df37064d109
|
|||
RUN pacman -Syyu --noconfirm \
|
||||
&& pacman -Syyu --noconfirm git less vim sudo python-pip wget which pkgconf \
|
||||
&& pacman -Syyu --noconfirm cmake make gcc ninja meson shellcheck \
|
||||
&& pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0
|
||||
&& pacman -Syyu --noconfirm gtk4 gtkmm-4.0 boost spdlog fmt libxml++-5.0 gtest
|
||||
|
||||
# Create a non-root user 'dev'
|
||||
RUN useradd -ms /bin/bash dev \
|
||||
|
@ -37,23 +37,25 @@ ADD https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}/L
|
|||
|
||||
# Create the LLVM directory and extract only binaries into it
|
||||
RUN sudo mkdir -p /home/LLVM-${LLVM_VER}
|
||||
RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-19 \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/lld \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/ld.lld \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/ld64.lld \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-scan-deps \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/llvm-symbolizer \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-format \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-tidy \
|
||||
LLVM-${LLVM_VER}-Linux-X64/bin/clang-apply-replacements \
|
||||
LLVM-${LLVM_VER}-Linux-X64/include/ \
|
||||
LLVM-${LLVM_VER}-Linux-X64/lib/ \
|
||||
LLVM-${LLVM_VER}-Linux-X64/libexec/ \
|
||||
LLVM-${LLVM_VER}-Linux-X64/local/ \
|
||||
LLVM-${LLVM_VER}-Linux-X64/share/
|
||||
RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1
|
||||
#RUN sudo tar -xJf /home/artifacts/LLVM-${LLVM_VER}-Linux-X64.tar.xz -C /home/LLVM-${LLVM_VER} --strip-components=1 \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clangd \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-19 \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang++ \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/lld \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/ld.lld \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/ld64.lld \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-scan-deps \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/llvm-symbolizer \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-format \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-tidy \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/bin/clang-apply-replacements \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/include/ \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/lib/ \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/libexec/ \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/local/ \
|
||||
# LLVM-${LLVM_VER}-Linux-X64/share/
|
||||
|
||||
# Add /home/LLVM-${LLVM_VER}/bin to the PATH environment variable
|
||||
ENV PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <spdlog/common.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <boost/asio/co_spawn.hpp>
|
||||
|
@ -14,11 +15,20 @@ auto Coroutine() -> boost::asio::awaitable<void> {
|
|||
auto client = co_await larra::xmpp::client::CreateClient<larra::xmpp::PrintStream<boost::asio::ip::tcp::socket>>(
|
||||
larra::xmpp::PlainUserAccount{.jid = {.username = "test1", .server = "localhost"}, .password = "test1"},
|
||||
{.useTls = larra::xmpp::client::Options::kNever});
|
||||
/*
|
||||
co_await std::visit(
|
||||
[](auto& client) -> boost::asio::awaitable<void> {
|
||||
SPDLOG_INFO("Send presence: Available");
|
||||
co_await client.Send(larra::xmpp::presence::c2s::Available{});
|
||||
},
|
||||
client);
|
||||
*/
|
||||
|
||||
std::visit(
|
||||
[](auto& client) -> boost::asio::awaitable<void> {
|
||||
co_await client.UpdateListOfContacts();
|
||||
},
|
||||
client);
|
||||
} catch(const std::exception& err) {
|
||||
SPDLOG_ERROR("{}", err.what());
|
||||
co_return;
|
||||
|
@ -27,7 +37,7 @@ auto Coroutine() -> boost::asio::awaitable<void> {
|
|||
}
|
||||
|
||||
auto main() -> int {
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
boost::asio::io_context io_context;
|
||||
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
|
||||
io_context.run();
|
||||
|
|
|
@ -21,7 +21,14 @@
|
|||
#include <larra/user_account.hpp>
|
||||
#include <larra/xml_stream.hpp>
|
||||
#include <ranges>
|
||||
#include <utility>
|
||||
#include "larra/iq.hpp"
|
||||
#include "larra/roster.hpp"
|
||||
|
||||
namespace rng = std::ranges;
|
||||
namespace views = std::views;
|
||||
namespace iq = larra::xmpp::iq;
|
||||
|
||||
namespace larra::xmpp {
|
||||
|
||||
constexpr auto kDefaultXmppPort = 5222;
|
||||
|
@ -30,9 +37,6 @@ constexpr auto kDefaultXmppPort = 5222;
|
|||
|
||||
namespace larra::xmpp::client {
|
||||
|
||||
namespace rng = std::ranges;
|
||||
namespace views = std::views;
|
||||
|
||||
template <typename Connection>
|
||||
struct Client {
|
||||
constexpr Client(BareJid jid, XmlStream<Connection> connection) : jid(std::move(jid)), connection(std::move(connection)) {};
|
||||
|
@ -72,11 +76,19 @@ struct Client {
|
|||
[[nodiscard]] constexpr auto Jid() const -> const BareJid& {
|
||||
return this->jid;
|
||||
}
|
||||
[[nodiscard]] auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
|
||||
Iq<iq::Get<Roster>>
|
||||
this->Send();
|
||||
|
||||
auto UpdateListOfContacts() -> boost::asio::awaitable<void> {
|
||||
SPDLOG_INFO("Send IQ: Get::Roster");
|
||||
co_await this->Send(::iq::GetRoster{});
|
||||
|
||||
::iq::ResultRoster roster = co_await connection.template Read<::iq::ResultRoster>();
|
||||
for (const auto& jid : roster.payload.items) {
|
||||
SPDLOG_INFO("\t'{}'", ToString(jid));
|
||||
}
|
||||
co_return;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
bool active = true;
|
||||
XmlStream<Connection> connection{};
|
||||
|
|
|
@ -1,76 +1,61 @@
|
|||
#pragma once
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <larra/jid.hpp>
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include <larra/iq.hpp>
|
||||
|
||||
namespace larra::xmpp::iq {
|
||||
|
||||
struct Roster {
|
||||
static constexpr auto kDefaultName = "query";
|
||||
static constexpr auto kDefaultNamespace = "jabber:iq:roster";
|
||||
|
||||
std::vector<BareJid> items;
|
||||
|
||||
friend constexpr auto operator<<(xmlpp::Element* element, const Roster& roster) {
|
||||
}
|
||||
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Roster {
|
||||
const auto& item_nodes = element->get_children("item");
|
||||
if(item_nodes.empty()) {
|
||||
SPDLOG_DEBUG("No items at Iq::Roster");
|
||||
}
|
||||
|
||||
return {
|
||||
.items = item_nodes
|
||||
| std::views::transform([](const xmlpp::Node* node) {
|
||||
auto item_element = dynamic_cast<const xmlpp::Element*>(node);
|
||||
if (!item_element) {
|
||||
throw std::runtime_error("Can't convert xmlpp::Node to xmlpp::Element");
|
||||
}
|
||||
|
||||
auto jid_ptr = item_element->get_attribute("jid");
|
||||
if (!jid_ptr) {
|
||||
throw std::runtime_error("Not found attribute 'jid' for parse Roster item");
|
||||
}
|
||||
|
||||
return BareJid::Parse(jid_ptr->get_value());
|
||||
})
|
||||
| std::ranges::to<std::vector<BareJid>>()};
|
||||
}
|
||||
|
||||
/*
|
||||
namespace larra::xmpp::presence {
|
||||
|
||||
namespace c2s {
|
||||
|
||||
struct Unavailable {
|
||||
static constexpr auto kDefaultName = "presence";
|
||||
friend constexpr auto operator<<(xmlpp::Element* element, const Unavailable&) {
|
||||
element->set_attribute("type", "unavailable");
|
||||
}
|
||||
[[nodiscard]] static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<Unavailable> {
|
||||
if(auto type = element->get_attribute("type")) {
|
||||
if(type->get_value() == "unavailable") {
|
||||
return Unavailable{};
|
||||
};
|
||||
friend constexpr auto operator<<(std::iostream& io, const Roster& roster) {
|
||||
for (const auto& jid : roster.items) {
|
||||
io << ToString(jid) << ' ';
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Unavailable {
|
||||
return Unavailable::TryParse(element).value();
|
||||
}
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
struct Available {
|
||||
static constexpr auto kDefaultName = "presence";
|
||||
friend constexpr auto operator<<(xmlpp::Element*, const Available&) {
|
||||
}
|
||||
[[nodiscard]] static constexpr auto TryParse(xmlpp::Element* element) -> std::optional<Available> {
|
||||
return Unavailable::TryParse(element).has_value() ? std::nullopt : std::optional{Available{}};
|
||||
}
|
||||
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Available {
|
||||
return Available::TryParse(element).value();
|
||||
}
|
||||
};
|
||||
using GetRoster = Get<Roster>;
|
||||
using ResultRoster = Result<Roster>;
|
||||
|
||||
} // namespace c2s
|
||||
} // namespace larra::xmpp::iq
|
||||
|
||||
using ClientToServer = std::variant<c2s::Unavailable, c2s::Available>;
|
||||
|
||||
struct Initial {
|
||||
static constexpr auto kDefaultName = "presence";
|
||||
FullJid from;
|
||||
BareJid to;
|
||||
template <typename Self>
|
||||
[[nodiscard]] constexpr auto From(this Self&& self, BareJid value) -> std::decay_t<Self> {
|
||||
return utils::FieldSetHelper::With<"from", Initial>(std::forward<Self>(self), std::move(value));
|
||||
}
|
||||
template <typename Self>
|
||||
[[nodiscard]] constexpr auto To(this Self&& self, BareJid value) -> std::decay_t<Self> {
|
||||
return utils::FieldSetHelper::With<"to", Initial>(std::forward<Self>(self), std::move(value));
|
||||
}
|
||||
friend constexpr auto operator<<(xmlpp::Element* element, const Initial& presence) {
|
||||
element->set_attribute("from", ToString(presence.from));
|
||||
element->set_attribute("to", ToString(presence.to));
|
||||
}
|
||||
[[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> Initial {
|
||||
auto from = element->get_attribute("from");
|
||||
if(!from) {
|
||||
throw std::runtime_error("Not found attribute from for Parse presence::Initial");
|
||||
}
|
||||
auto to = element->get_attribute("to");
|
||||
if(!to) {
|
||||
throw std::runtime_error("Not found attribute to for Parse presence::Initial");
|
||||
}
|
||||
return {.from = FullJid::Parse(from->get_value()), .to = BareJid::Parse(to->get_value())};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace larra::xmpp
|
||||
*/
|
||||
namespace larra::xmpp {
|
||||
using IqRoster = Iq<iq::Roster>;
|
||||
}
|
||||
|
|
|
@ -87,6 +87,10 @@ struct SerializationBase {
|
|||
}) {
|
||||
return T::StartCheck(element);
|
||||
} else {
|
||||
if (element)
|
||||
{
|
||||
SPDLOG_DEBUG("kDefaultName: {}, get_name: {}", kDefaultName, element->get_name());
|
||||
}
|
||||
return element && element->get_name() == kDefaultName;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue